Re: [R] Creating new variable with maximum visit date by group_id

2011-08-24 Thread Dennis Murphy
Hi: Since you tried several functions (reasonably so IMO), here is how they would work in this problem, in addition to the solutions already supplied. Some data massaging before starting, taking your data as input, saved into an object named visits: visits <- structure(list(unique_id = c(1L, 1L,

Re: [R] Creating new variable with maximum visit date by group_id

2011-08-24 Thread Jean V Adams
Try this: require(zoo) lvd <- tapply(df$visit_date, df$unique_id, max) index <- tapply(df$visit_date, df$unique_id) df$last_visit_date <- as.Date(lvd[index]) Jean Kathleen Rollet wrote on 08/24/2011 04:15:45 PM: > > Dear R users, > > I am encoutering the following problem: I have a dataset wit

Re: [R] Creating new variable with maximum visit date by group_id

2011-08-24 Thread David Winsemius
On Aug 24, 2011, at 5:15 PM, Kathleen Rollet wrote: Dear R users, I am encoutering the following problem: I have a dataset with a 'unique_id' and different 'visit_date' (formatted as.Date, "%d/%m/ %Y") per unique_id. I would like to create a new variable with the most recent date of visit

[R] Creating new variable with maximum visit date by group_id

2011-08-24 Thread Kathleen Rollet
Dear R users, I am encoutering the following problem: I have a dataset with a 'unique_id' and different 'visit_date' (formatted as.Date, "%d/%m/%Y") per unique_id. I would like to create a new variable with the most recent date of visit per unique_id as shown below. unique_id visit_date