I have a beginner question. After I finally get the data to a data.frame that I can work with I have the following a data frame that is fairly long:> length(r2007)[1] 17409 If I look at the first element:> r2007[1]$`100009` DayOfYear Quantity 1 66 1 2 128 1 3 137 1 4 193 1 Now how do I get the length of this list (actually it is another data.frame)? I have tried:> length(r2007[1])[1] 1 Not right. And:> length(r2007[1]$DayOfYear)[1] 0 Also not right the length returned should be 4 from the output above. I want to use this to iterate through the object. So in the outer loop I would have: for(i in 1:length(r2007)) { . . . . } I need to form an inner loop and an expression that returns each row (as above). Any ideas? Thank you. Kevin
On Aug 8, 2008, at 5:18 PM, <rkevinburton at charter.net> <rkevinburton at charter.net> wrote:> I have a beginner question. After I finally get the data to a > data.frame that I can work with I have the following a data frame > that is fairly long: > >> length(r2007) > [1] 17409 > > If I look at the first element: > >> r2007[1] > $`100009` > DayOfYear Quantity > 1 66 1 > 2 128 1 > 3 137 1 > 4 193 1 > > Now how do I get the length of this list (actually it is another > data.frame)? > > I have tried: > >> length(r2007[1]) > [1] 1 > > Not right. And: > >> length(r2007[1]$DayOfYear) > [1] 0 > > Also not right the length returned should be 4 from the output > above. I want to use this to iterate through the object. So in the > outer loop I would have: > > for(i in 1:length(r2007)) > { > . . . . > } > > I need to form an inner loop and an expression that returns each > row (as above). > >Hi, Use nrow() and ncol() to determine the number of rows and columns of a data frame. Cheers, Ben Ben Tupper PemaquidRiver at tidewater.net I GoodSearch for Ashwood Waldorf School. Raise money for your favorite charity or school just by searching the Internet with GoodSearch - www.goodsearch.com - powered by Yahoo!
I have a related question...I have a data frame similar with 74 rows that I created with "header=TRUE", but when I try to coerce one of the data frame columns into a vector, it shows up as having length 1, even though when I print it, it shows 74 elements:> VAL <- c(DailyDiary[1]) > VAL > [1] 3 3 3 2 3 3 4 4 3 3 2 1 1 4 3 3 2 3 3 2 2 3 3 3 1 2 2[28] 1 1 3 3 3 2 4 3 2 3 4 3 3 3 3 4 3 2 3 2 3 1 2 1 2 3 1 [55] 0 3 2 4 3 1 2 3 1 1 1 4 3 2 1 2 3 3 3 2>length(VAL)[1] 1 On the other hand, I can easily coerce the row names to a vector of length 74> partf <- row.names(DailyDiary) > length(partf)[1] 74 What I would like to do is make VAL into a vector with length 74 instead of length 1 so I can sort it using use "partf" as factors. I tried "as.vector", but it doesn't let you specify the length. Any ideas? Thanks, and sorry if I'm being unclear or stupid, I'm a newbie :) Logan -- View this message in context: http://r.789695.n4.nabble.com/Length-of-data-frame-column-tp864585p3903892.html Sent from the R help mailing list archive at Nabble.com.