r - Are all dates in order -
i trying apply diff() on series of columns containing dates. interested in difference between date1-date2, date2-date3, etc.
i interested in:
- the actual difference between dates (days)
- if dates of row in order (diff >= 0, row)
i can use diff() on series of dates (e.g. on first row --> diff(unlist(df1[1,])) ). need apply per row, guess using apply(), reason can't work out. dates missing, allowed in study.
hopefully easy guys...
df <- structure(list(date1 = structure(c(-10871, -13634, -15937, -15937, -290, -2323), class = "date"), date2 = structure(c(16678, na,16037, 16659, 16538, 16626), class = "date"), date3 = structure(c(16685,16688, na, 16659, 16568, 16672), class = "date"), date4 = structure(c(16701, 16695, 16670, 16661, 16582, 16672), class = "date"), date5 = structure(c(16709, 16695, 16661, 16667, 16619, 16692), class = "date")), .names = c("date1","date2", "date3", "date4", "date5"), row.names = c("2", "3", "4", "5", "6", "7"), class = "data.frame") df
you can try this:
apply(df, 1, function(x) identical(sort(as.date(x)), as.date(x[!is.na(x)]))) it providing output this, says whether particular rows dates in sorted order.
2 3 4 5 6 7 true true false true true true
Comments
Post a Comment