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 -

Python Tornado package error when running server -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -