[R] Finding the two most recent dates

Dieter Menne dieter.menne at menne-biomed.de
Mon Sep 6 15:01:32 CEST 2010


Nathalie,

your method of sending sample data is fine. 

dt = 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")

# The most recent date
iRecent =  which.max(dt$bp_date) # index of record with most recent date
dt[iRecent,]
# ind_1     2010-06-24 2010-01-13 126  60

# To Paul Hiemstra: we have the integer representation of date here
as.integer(dt$bpdate[iRecent])

I believe that the description of your problem is not complete (homework?),
because there is only on subject and one 1st event. So please try to restate
the rest of the problem.

Dieter





-- 
View this message in context: http://r.789695.n4.nabble.com/Finding-the-two-most-recent-dates-tp2528185p2528346.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list