本文介绍了无法在演员表中使用`fill = NA`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

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'

这是上面的rep.data数据框:

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")

推荐答案

使用NA_real_代替NA,因为dcast也会匹配类型.

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

这篇关于无法在演员表中使用`fill = NA`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 06:44