Convert 3-column dates in data to class Date
Return a data.frame
with columns of
class "Date" replacing all 3-column dates.
Dates3to1(data, YMD=c('Year', 'Month', 'Day'))
data |
a |
YMD |
a character vector of length 3 of patterns to use
in |
The data sets from the
Correlates
of War project include dates coded in triples of
columns with names like c("StartMonth1",
"StartDay1", "StartYear1", "EndMonth1", ...,
"EndYear2")
. This function will accept a
data.frame
obtained via
read.csv
of such a file and replace
each such triple with a singe column of class 'Date'
combining the triple appropriately.
Return a data.frame
containing the
information in data
reformatted as described
above.
Spencer Graves
cow0 <- data.frame(rec=1:3, startMonth=4:6, startDay=7:9, startYear=1971:1973, endMonth1=10:12, endDay1=13:15, endYear1=1974:1976, txt=letters[1:3]) cow0. <- Dates3to1(cow0) # check cow0x <- data.frame(rec=1:3, txt=letters[1:3], start=as.Date(c('1971-04-07', '1972-05-08', '1973-06-09')), end1=as.Date(c('1974-10-13', '1975-11-14', '1976-12-15')) ) all.equal(cow0., cow0x)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.