Re: [R] get latest dates for different people in a dataset

2015-01-26 Thread Tan, Richard
Thank you! -Original Message- From: Chel Hee Lee [mailto:chl...@mail.usask.ca] Sent: Friday, January 23, 2015 8:09 PM To: Tan, Richard; 'r-help@R-project.org' Subject: Re: [R] get latest dates for different people in a dataset do.call(rbind, lapply(split(data, data$Name), function(x

Re: [R] get latest dates for different people in a dataset

2015-01-26 Thread Tan, Richard
Thank you! -Original Message- From: David Barron [mailto:dnbar...@gmail.com] Sent: Saturday, January 24, 2015 7:56 AM To: Tan, Richard; r-help@R-project.org Subject: Re: [R] get latest dates for different people in a dataset Hi Richard, You could also do it using the package dplyr

Re: [R] get latest dates for different people in a dataset

2015-01-26 Thread Tan, Richard
Thank you! From: William Dunlap [mailto:wdun...@tibco.com] Sent: Friday, January 23, 2015 7:14 PM To: Tan, Richard Cc: r-help@R-project.org Subject: Re: [R] get latest dates for different people in a dataset Here is one way. Sort the data.frame, first by Name then break ties with CheckInDate

Re: [R] get latest dates for different people in a dataset

2015-01-25 Thread Göran Broström
On 2015-01-24 01:14, William Dunlap wrote: Here is one way. Sort the data.frame, first by Name then break ties with CheckInDate. Then choose the rows that are the last in a run of identical Name values. I do it by sorting by the reverse order of CheckinDate (last date first) within Name,

Re: [R] get latest dates for different people in a dataset

2015-01-25 Thread William Dunlap
dLatestVisit - dSorted[!duplicated(dSorted$Name), ] I guess it is faster, but who knows? You can find out by making a function that generates datasets of various sizes and timing the suggested algorithms. E.g., makeData - function(nPatients, aveVisitsPerPatient, uniqueNameDate = TRUE){

Re: [R] get latest dates for different people in a dataset

2015-01-25 Thread Göran Broström
See inline; On 2015-01-25 20:27, William Dunlap wrote: dLatestVisit - dSorted[!duplicated(dSorted$__Name), ] I guess it is faster, but who knows? You can find out by making a function that generates datasets of various sizes and timing the suggested algorithms. E.g., makeData -

Re: [R] get latest dates for different people in a dataset

2015-01-24 Thread David Barron
Hi Richard, You could also do it using the package dplyr: dta - data.frame(Name=c('John','Mary','Sam','John'), CheckInDate=as.Date(c('1/3/2014','1/3/2014','1/4/2014','1/4/2014'), format='%d/%m/%Y'), Temp=c(97,98.1,97.5,99))

[R] get latest dates for different people in a dataset

2015-01-23 Thread Tan, Richard
Hi, Can someone help for a R question? I have a data set like: NameCheckInDate Temp John 1/3/2014 97 Mary 1/3/2014 98.1 Sam 1/4/2014 97.5 John 1/4/2014 99 I'd like to return a dataset that for each Name, get the

Re: [R] get latest dates for different people in a dataset

2015-01-23 Thread William Dunlap
Here is one way. Sort the data.frame, first by Name then break ties with CheckInDate. Then choose the rows that are the last in a run of identical Name values. txt - NameCheckInDate Temp + John 1/3/2014 97 + Mary 1/3/2014 98.1 + Sam 1/4/2014

Re: [R] get latest dates for different people in a dataset

2015-01-23 Thread Chel Hee Lee
do.call(rbind, lapply(split(data, data$Name), function(x) x[order(x$CheckInDate),][nrow(x),])) Name CheckInDate Temp John John 2014-04-01 99.0 Mary Mary 2014-03-01 98.1 Sam Sam 2014-04-01 97.5 Is this what you are looking for? I hope this helps. Chel Hee Lee On 01/23/2015 05:43