Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use `fill = NA` in cast

Tags:

r

na

I received the following error:

dcast(rep.data, country ~ variable, mean, fill=NA)

Error in vapply(indices, fun, .default) : values must be type 'logical',
but FUN(X[[4]]) result is type 'double'

Here is the 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")
like image 697
Heisenberg Avatar asked Mar 25 '14 03:03

Heisenberg


1 Answers

Use NA_real_ instead of NA, since dcast matches type as well.

like image 180
Robert Krzyzanowski Avatar answered Oct 03 '22 07:10

Robert Krzyzanowski