# [R] interesting feature

Douglas Bates bates at stat.wisc.edu
Wed Feb 18 18:14:23 CET 2004

```Svetlana Eden <svetlana.eden at vanderbilt.edu> writes:

> Hi, everybody.
> This was an interesting discussion last time and it helped me a lot.
>
> Could you please have a look at some feature and tell me
> why it was designed this way
> (my questions are under #########)
>
> > x = c(1, 10)
> > y = c(99, 55)
> > d <- data.frame(x = x, y = y)
> > d
>    x  y
> 1  1 99
> 2 10 55
> > add <- data.frame(x = 14, y = 99)
>    x  y
> 1 14 99
> > d <- rbind(d, add)
> > d
>     x  y
> 1   1 99
> 2  10 55
> 11 14 99
> ######### it would be more natural to index the rows: 1,2,3 instead of
> #1,2,11  ?!

It's not the number 11, it is the string "11".

Row names are character strings.  In your original data frame the row
names were "1" and "2" for the first frame and "1" for the second.
The rbind function should not create a duplicate row name so it
prepended a "1" to all the names in the second frame.  That explains
the "11" and "12" in your last example.  They are simply the original
names "1" and "2" with a "1" prepended to them.

> >
> > d[3,1]
> [1] 14
> > d[11,1]

Try d["11", 1]

> [1] NA
> ######### especially if index '11' is not functioning...
> >
> > add1 <- data.frame(x = 10, y = 87)
> > d <- rbind(d, add)
> ######### now I would think that the next index should be 21, BUT:
> > d
>     x  y
> 1   1 99
> 2  10 55
> 11 14 99
> 12 10 87
> ######### so what is the intuition of such indexing?

```