Displaying 1 result from an estimated 1 matches for "numsplits".
2012 Nov 09
2
Creating yyyymm regexp strings on the fly for aggregation.
...plitIt(1:12, 4)
$`0`
[1] 1 2 3
$`1`
[1] 4 5 6
$`2`
[1] 7 8 9
$`3`
[1] 10 11 12
I am splitting 12 months into 6-month or quarterly chunks. I can also use the function to create monthly or segments or one big annual segment.
Here is a function that I developed:
groupingStrings<-function(yrs, numSplits) {
unlist(lapply(yrs, function(x){ paste(x,formatC(numSplits, width = 2, flag = 0), collapse = "|", sep = "")}))
}
Here is an example of running the function:
groupingStrings(2004:2006, 1:3)
[1] "200401|200402|200403" "200501|200502|200503" "200601|200...