r - Is something new with factor()? -
there issues examples of "epitools" package, example epicurve.dates
function.
here simple example of epidemic curve (by days, epicurve.dates
)
sampdates <- seq(as.date("2014-01-01"), sys.date(), 1) x <- sample(sampdates, 100, rep=true) epicurve.dates(x)
this resulted plot :
nothing ploted, , if in epicurve.dates
code can see problem happened when try encode date vector factor. nas
produced.
format <- "%y-%m-%d"; before <- after <- 7 dates0 <- as.date(x, format = format) min.date <- min(dates0, na.rm = true) - before max.date <- max(dates0, na.rm = true) + after cdates <- seq(min.date, max.date, = 1) > factor(dates0, levels = cdates) [1] <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> [24] <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> [47] <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> [70] <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> <na> [93] <na> <na> <na> <na> <na> <na> <na> <na> 51 levels: 2013-12-25 2013-12-26 2013-12-27 2013-12-28 2013-12-29 2013-12-30 2013-12-31 2014-01-01 ... 2014-02-13
in ?factor
can read :
if x[i] equals levels[j], i-th element of result j. if no match found x[i] in levels (which happen excluded values) i-th element of result set na.
but when test if x[i] equals levels[j], it's true ...
> sum(dates0 %in% cdates) == length(dates0) [1] true
what's wrong here ?
(it works example factor(dates0, levels = factor(cdates))
)
example official epicurve.dates
documentation guess used worked, looked changes of factor
function on http://stat.ethz.ch/r-manual/r-devel/doc/html/news.html example find nothing.
did change ?
Comments
Post a Comment