month increment for chron dates
I don't know if this is any faster but it does not use any loops or apply
so maybe it is. x is assumed to be a vector chron dates. Note that
the question is not well specified for days near the end of the month
and I have not addressed that.
with(month.day.year(x), {
year <- ifelse(month > 9, year + 1, year)
month <- ifelse(month > 9, month - 9, month + 3)
chron(paste(month, day, year, sep = "/"))
} )
On 9/18/05, bmw8042 <bmw8042 at verizon.net> wrote:
I have a vector of over 7,000 chron dates in the format "mm/dd/yy". I need to increment each date in the vector by a standard number of months. Lapply with seq.dates is working OK; this increments the vector x by 3 months: dates(unlist(lapply(x, function(g) seq.dates(g, by="months", length=4)[4]))) But this takes about 55 seconds to run on a Windows XP 1.8 Pentium 512 RAM PC with R version 2.0.0 Can you recommend a more efficient way to do this? thanks for your advice Brian Winkler Controller BPS Trade Services CGI
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html