[R] Sequence for repeated numbers

2010-12-01 Thread Luana Marotta
Hello fellows, I would like to create a sequence for repeated numbers in a dataset. For example: ID - c(1:20) grade - c(4,4,4,5,5,7,7,7,7,8,8,8,9,9,9,9,9,10,10,10) Data: ID Grade 1 4 2 4 3 4 4 5 5 5 6 7 7 7 8 7 9 7 (...) I would like to create a variable sequence: Data: ID

Re: [R] Sequence for repeated numbers

2010-12-01 Thread Jonathan P Daily
... imbue it. - Jubal Early, Firefly r-help-boun...@r-project.org wrote on 12/01/2010 11:08:06 AM: [image removed] [R] Sequence for repeated numbers Luana Marotta to: r-help, r-help-request 12/01/2010 11:09 AM Sent by: r-help-boun...@r-project.org Hello fellows, I

Re: [R] Sequence for repeated numbers

2010-12-01 Thread Jorge Ivan Velez
Hi Luana, Try this: ID - 1:20 grade - c(4, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10) d - data.frame(ID, grade) d$Sequence - do.call(c, sapply(rle(grade)$lengths, seq)) d HTH, Jorge On Wed, Dec 1, 2010 at 11:08 AM, Luana Marotta wrote: Hello fellows, I would like to

Re: [R] Sequence for repeated numbers

2010-12-01 Thread Phil Spector
Luana - It's probably not the most efficient way, but here's a solution that's not dependent on the grades being sorted: grade - c(4,4,4,5,5,7,7,7,7,8,8,8,9,9,9,9,9,10,10,10) unlist(sapply(rle(grade)$lengths,function(x)seq(1,x))) [1] 1 2 3 1 2 1 2 3 4 1 2 3 1 2 3 4 5 1 2 3

Re: [R] Sequence for repeated numbers

2010-12-01 Thread Greg Snow
Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Luana Marotta Sent: Wednesday, December 01, 2010 9:08 AM To: r-help; r-help-request Subject: [R] Sequence for repeated numbers