[R] Length of data.frame column

Ben Tupper PemaquidRiver at tidewater.net
Sat Aug 9 03:08:53 CEST 2008


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!



More information about the R-help mailing list