##
## 1. character vector
##
colNames <- c('war', 'StartMonth1',
'StartDay1', 'StartYear1',
'EndMonth1', 'EndMonth2',
'EndDay2', 'EndYear2', 'Initiator')
colNums <- dateCols(colNames)
# Should issue a warning:
# Warning message:
# In dateCols(colNames) :
# number of matches for Year = 2
# != number of matches for Month = 3
# check
colN <- list(Start1=c(Year=4, Month=2, Day=3),
End2=c(Year=8, Month=6, Day=7) )
stopifnot(
all.equal(colNums, colN)
)
##
## 2. array
##
A <- matrix(ncol=length(colNames),
dimnames=list(NULL, colNames))
Anums <- dateCols(A)
# check
stopifnot(
all.equal(Anums, colN)
)
Run the code above in your browser using DataLab