# [R] interesting feature

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Feb 18 18:04:55 CET 2004

```You are adding a row with name "1" each time.  R just adds a suffix to
make it unique.  What you call indices are the *row names* of the data
frame.

Suppose the row name had been "Eden".  Then "Eden1" and "Eden2" make more

On Wed, 18 Feb 2004, Svetlana Eden wrote:

> 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  ?!
> >
> > d[3,1]
> [1] 14
> > d[11,1]
> [1] NA
> ######### especially if index '11' is not functioning...

You need "11": it is a row name and not a row index.

> > 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?

--
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

```