r - Cannot use `fill = NA` in cast -
i received following error:
dcast(rep.data, country ~ variable, mean, fill=na) error in vapply(indices, fun, .default) : values must type 'logical', fun(x[[4]]) result type 'double'
here rep.data
data frame above:
structure(list(id = c("mrt1996", "bfa1982", "lbr1990", "ukr2000", "mng1993", "ven1992", "omn1987", "lao1996", "omn1982", "syr1993" ), wbcode = c("mrt", "bfa", "lbr", "ukr", "mng", "ven", "omn", "lao", "omn", "syr"), polcode = c("maa", "bfo", "lbr", "ukr", "mon", "ven", "oma", "lao", "oma", "syr"), country = c("mauritania", "burkina faso", "liberia", "ukraine", "mongolia", "venezuela, rb", "oman", "lao pdr", "oman", "syrian arab republic"), cid = c(117l, 14l, 96l, 174l, 115l, 179l, 130l, 94l, 130l, 161l), year = c(1996l, 1982l, 1990l, 2000l, 1993l, 1992l, 1987l, 1996l, 1982l, 1993l ), variable = structure(c(9l, 7l, 22l, 26l, 18l, 24l, 10l, 7l, 16l, 25l), .label = c("fdi", "gdp", "l.gdp", "gdp.pc", "l.gdp.pc", "growth", "govex", "deficit", "r.usa", "polity", "polpersist", "varpol.5", "bonds", "eqty", "net.port.in", "portin.gdp", "external.debt", "external.debt.gdp", "official.xr.pct", "inflation.deflt", "iir.annual", "default", "cum.default.60", "pct.default.60", "cum.default.80", "pct.default.80", "tor80s", "tor90s", "events", "tor5", "turn" ), class = "factor"), value = c(6.2, 15.56, 1, 14.29, 74.04, 27.27, 0, 7.92, 0, 0)), .names = c("id", "wbcode", "polcode", "country", "cid", "year", "variable", "value"), row.names = c(26927l, 18978l, 67240l, 81096l, 55030l, 74901l, 30322l, 20280l, 49085l, 77731l), class = "data.frame")
use na_real_
instead of na
, since dcast
matches type well.
Comments
Post a Comment