[R] strange row numbering after rbind-ing a list

Sarah Goslee sarah.goslee at gmail.com
Fri Dec 2 00:26:18 CET 2011


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


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list