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

angular - DownloadURL return null in below code -

meteor - inserting data to database gives error "insert failed: Method '/texts/insert' not found" -