[R] strange row numbering after rbind-ing a list
Carl Witthoft
carl at witthoft.com
Fri Dec 2 02:54:14 CET 2011
Sorry -- I meant to write 'row names,' but the question specifically is
where those unlikely numbers come from. So I guess it comes down to
why, when 'bar' is the first item, the row name is assigned '2' rather
than '1' .
On 12/1/11 6:26 PM, Sarah Goslee wrote:
> Those are row *names*, not row *numbers*. It's just that if you don't specify,
> numbers are assigned by default when creating a data frame.
>
> Your rbind() statements are implicitly creating a data frame, so the likely
> information is in ?data.frame:
>
> check.names: logical. If ‘TRUE’ then the names of the variables in the
> data frame are checked to ensure that they are syntactically
> valid variable names and are not duplicated. If necessary
> they are adjusted (by ‘make.names’) so that they are.
>
> By default, row.names=NULL and check.names=TRUE.
>
> See also ?rbind.data.frame
>
> Sarah
>
> On Thu, Dec 1, 2011 at 6:13 PM, Carl Witthoft<carl at witthoft.com> wrote:
>> "Not that it really matters, but"
>> Can someone explain how the row numbers get assigned in the following
>> sequence? It looks like something funky happens when rbind() coerces 'bar'
>> into a dataframe.
>> In either sequence of rbind below, once you get past the first two rows, the
>> row numbers count normally.
>>
>>
>> Rgames> (foo<-data.frame(x=5,y=4,r=3))
>> x y r
>> 1 5 4 3
>> Rgames> (bar<-list(x=4,y=5,r=6))
>> $x
>> [1] 4
>>
>> $y
>> [1] 5
>>
>> $r
>> [1] 6
>>
>> Rgames> (foobar<- rbind(foo,bar))
>> x y r
>> 1 5 4 3
>> 2 4 5 6
>>
>> Rgames> (foobar<- rbind(foobar,bar))
>> x y r
>> 1 5 4 3
>> 2 4 5 6
>> 3 4 5 6
>>
>>
>> Rgames> (barfoo<-rbind(bar,foo))
>> x y r
>> 2 4 5 6
>> 21 5 4 3
>>
>> Rgames> (barfoo<-rbind(barfoo,foo))
>> x y r
>> 2 4 5 6
>> 21 5 4 3
>> 3 5 4 3
>
>
--
Sent from my Cray XK6
"Pendeo-navem mei anguillae plena est."
More information about the R-help
mailing list