[R] Finding the two most recent dates
Paul Hiemstra
p.hiemstra at geo.uu.nl
Mon Sep 6 14:04:46 CEST 2010
Hi Natalie,
By far the easiest thing to do is to convert the date to a special date
class. See as.POSIXct for example. I'm not sure that 14784 means, nor
what the data says in the bp_date column. Probably the two combine into
a specific date?
Once you've converted the columns into a POSIXct object, you can use the
min() function to find the minimum.
cheers,
Paul
On 09/06/2010 12:45 PM, Newbie19_02 wrote:
> Dear R help,
>
> I have the following data frame:
>
> structure(list(prochi = c("ind_1", "ind_1", "ind_1",
> "ind_1", "ind_1", "ind_1", "ind_1", "ind_1",
> "ind_1", "ind_1"), date_1st_event = structure(c(14784,
> 14784, 14784, 14784, 14784, 14784, 14784, 14784, 14784, 14784
> ), class = "Date"), bp_date = structure(c(12660, 14571, 13392,
> 13080, 12012, 13080, 13894, 14622, 12654, 13894), class = "Date"),
> SBP = c(135L, 160L, 135L, 153L, 150L, 153L, 151L, 126L, 150L,
> 151L), DBP = c(85L, 80L, NA, 79L, 82L, 79L, 76L, 60L, 82L,
> 91L)), .Names = c("prochi", "date_1st_event", "bp_date", "SBP",
> "DBP"), row.names = 108:117, class = "data.frame")
>
> It consists of repeated measures for the same individual. What I want to do
> is find the two most recent blood pressure readings (SBP and DBP) using
> date_1st_event and bp_date. What I would do to find the most recent date is
> to subtract date_1st_event-bp_date and then aggregate by min. I'm not sure
> how to find the two most recent dates.
>
> Are there some functions that can help me or will I have to write a function
> from scratch. Any help just to point me in the right direction.
>
> Thanks,
> Natalie
>
--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone: +3130 253 5773
http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770
More information about the R-help
mailing list