r - Subset rows from list of dataframe -


i want subset rows,say 130:150, in each dataframe present in list. have written below code subset:

test<-lapply(res,subset, [130:150,]) # res contains list of dataframes 

but code throwing below error:

error in res[130:150, ] : incorrect number of dimensions 

thanks in advance!

res <- list(mtcars,mtcars) lapply(res, function(x) return(x[2:4,])) 

is returning rows 2 4 of each dataframe. if want columns, use

lapply(res, function(x) return(x[,2:4])) 

or gregors solution lapply(res, "[", 2:4)


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -