Dates3to1: Convert 3-column dates in data to class Date

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Return a data.frame with columns of class "Date" replaceing all 3-column dates.

Usage

1
Dates3to1(data, YMD=c('Year', 'Month', 'Day'))

Arguments

data

a data.frame assumed to include dates coded in three column sets with names matching YMD.

YMD

a character vector of lenght 3 of patterns to use in grep to identify triples of columns coding YMD in col.names(data).

Details

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.

Value

Return a data.frame containing the information in data reformatted as described above.

Author(s)

Spencer Graves

See Also

dateCols Date3to1

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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)

Ecfun documentation built on Oct. 25, 2016, 12:19 p.m.

Search within the Ecfun package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs in the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.