I have a data.frame as follows:
dat <- structure(list(id = 1:4, date = structure(list(sec = c(0, 0,
0, 0), min = c(0L, 0L, 0L, 0L), hour = c(0L, 0L, 0L, 0L), mday = 1:4,
mon = c(0L, 0L, 0L, 0L), year = c(110L, 110L, 110L, 110L),
wday = c(5L, 6L, 0L, 1L), yday = 0:3, isdst = c(0L, 0L, 0L,
0L)), .Names = c("sec", "min", "hour", "mday", "mon", "year",
"wday", "yday", "isdst"), class = c("POSIXlt", "POSIXt")), name = c("george",
"paul", "john", "ringo")), .Names = c("id", "date", "name"), row.names = c(NA,
-4L), class = "data.frame")
To select the row with the oldest or most recent date I can use:
dat[(dat$date ==min(dat$date)),] and dat[(dat$date ==max(dat$date)),] respectively.
Is there a way to obtain the record for other dates such as the second oldest or the second most recent.
Thanks.
You can sort your data.frame and take the first or last rows.