Re: [R] Numbering entries for each subject

2011-09-21 Thread Jeff Newmiller
A$Session_id <- ave(rep(1,length(A$ID),A$ID,FUN=cumsum) --- Jeff Newmiller The . . Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Sof

Re: [R] Numbering entries for each subject

2011-09-21 Thread jim holtman
try this: > x <- read.table('clipboard') > x V1 V2 1 1 A 2 2 A 3 3 A 4 4 A 5 5 B 6 6 B 7 7 B 8 8 C 9 9 C 10 10 C 11 11 C 12 12 C > x$ID <- ave(x$V1, x$V2, FUN = function(a)seq(length(a))) > x V1 V2 ID 1 1 A 1 2 2 A 2 3 3 A 3 4 4 A 4 5 5 B 1 6

[R] Numbering entries for each subject

2011-09-21 Thread Toni Pitcher
Hi R Users I am hoping someone might be able to give some pointers on alternative code to the for loop described below. I have a dataset which is ordered by subject ID and date, what I would like to do is create a new variable that numbers the entries for each person (e.g. 1,2,3,) As an e