Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

number of rows each data frame in a list [duplicate]

Tags:

list

r

I have a list of data frames in R. They are created using lapply and read.csv commands. I want to know the number of rows of each data frame in the list. The nrow command does not work for this list. I am not sure may because it is a list. Any idea about counting the number of rows of each data frame in a list?

like image 942
maryam emami Avatar asked Sep 26 '12 20:09

maryam emami


2 Answers

Lists don't have rows. Use sapply to loop over the list:

sapply(data.frame.list, nrow)
like image 59
Joshua Ulrich Avatar answered Oct 19 '22 23:10

Joshua Ulrich


or lapply- the difference is in the output

lapply(data.frame.list, function(x) nrow(x))
like image 37
Andy Timmosn Avatar answered Oct 20 '22 00:10

Andy Timmosn