[R] Add number series to data frame

Sarah Goslee sarah.goslee at gmail.com
Tue Mar 6 18:37:24 CET 2012

I'd just sort them first, if you want consecutive numbers for each
value. (It would have been nice to specify that in the original

If you need for some reason to put them back in order, you can always
cbind(1:nrow(x), x) before sorting, to get an index to sort on after
you're done.

As always, there are other ways to do it.


On Tue, Mar 6, 2012 at 12:32 PM, syrvn <mentor_ at gmx.net> wrote:
> Hi Sarah,
> thanks a lot for this peace of code.
> Is it possible to give the second sequence of "B" in your second example
> (data frame b)
> the numbers 6, 7 and 8 instead of 1, 2 and 3 again? In my real data I have
> more columns than
> only those two and sometimes the are sorted differently so that column name
> rather looks like
> your second example (data frame b) rather than your first one.
> Regards

Sarah Goslee

More information about the R-help mailing list