Hi Petr,
that works great. thanks!
I was working my head off on that :)
--
View this message in context:
http://r.789695.n4.nabble.com/Add-number-series-to-data-frame-tp4450495p4452962.html
Sent from the R help mailing list archive at Nabble.com.
__
On Tue, Mar 06, 2012 at 09:32:37AM -0800, syrvn 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 th
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 colu
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
question.)
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
Here's one possible approach. It assumes that a$name is a factor, as
it is in your example, but does not require that each sequence has a
unique value (see second example).
> a <- data.frame(name = c(rep("A", 3), rep("B", 5), rep("C", 10)))
> data.frame(name=a, val=unlist(sapply(rle(as.numeric(a[,
5 matches
Mail list logo