Dear R users,
Followings are summary the solutions for my question.
All the way to Roma!
But vote #1 for Jim, the simplest solution.
Thank you all of you for yours quick response
Regards
Nguyen
# I have a data set sth like this:
set.seed(123);dat - data.frame(ID= c(rep(1,2),rep(2,3),
Just noticed one should use seq_along instead of seq in both
my post and Jim's to include the case where dat only has one
row.
On 4/2/07, Nguyen Dinh Nguyen [EMAIL PROTECTED] wrote:
Dear R users,
Followings are summary the solutions for my question.
All the way to Roma!
But vote #1 for Jim,
Dear R helpers
I have a data set sth like this:
set.seed(123);dat - data.frame(ID= c(rep(1,2),rep(2,3), rep(3,3), rep(4,4),
rep(5,5)),
var1 =rnorm(17, 35,2),
var2=runif(17,0,1))
dat
ID var1 var2
1 1 33.87905 0.02461368
2 1 34.53965 0.47779597
3
set.seed(123);dat - data.frame(ID= c(rep(1,2),rep(2,3), rep(3,3), rep(4,4),
rep(5,5)),
var1 =rnorm(17, 35,2),
var2=runif(17,0,1))
dat$order - ave(dat$ID, dat$ID, FUN=seq)
On 4/1/07, Nguyen Dinh Nguyen [EMAIL PROTECTED] wrote:
Dear R helpers
I have a data set
Assuming the ID's are contiguous, as in your example:
transform(dat, IDorder = seq(ID) - match(ID, ID) + 1)
On 4/1/07, Nguyen Dinh Nguyen [EMAIL PROTECTED] wrote:
Dear R helpers
I have a data set sth like this:
set.seed(123);dat - data.frame(ID= c(rep(1,2),rep(2,3), rep(3,3), rep(4,4),