Re: [R] reset row numbers when extracting a subset of a table

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue, 24 Jun 2008 12:22:00 -0400

I assume that by table you mean data frame. Using the built in data frame, BOD, try this:

> ix <- 2:4
> BOD[ix, ]

  Time demand

2    2   10.3
3    3   19.0
4    4   16.0

> data.frame(BOD[ix, ], row.names = seq_along(ix))
  Time demand
1    2   10.3
2    3   19.0
3    4   16.0


On Tue, Jun 24, 2008 at 11:23 AM, <naw3_at_duke.edu> wrote:
> Hi
>
> I created a new table by extracting only certain rows of table, but the row
> numbers in my new table correspond to those from the original table. Is there a
> way to reset the row numbers in my new table so that they start from one? like
> below:
>
> my table:
> COL1 COL2
> 17 v 45
> 18 b 14
> 25 x 98
>
> desired:
> COL1 COL2
> 1 v 45
> 2 b 14
> 3 x 98
>
> Thank you!
> -Nina
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 24 Jun 2008 - 16:30:34 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 24 Jun 2008 - 17:31:01 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive