Reputation: 1917
Why does the survey package in R return a mean value of 0 when calculating the mean of no data? Shouldn't the result be NA?
Example:
survey::svymean(
~x,
design = survey::svydesign(
ids = ~1,
weights = ~w,
data = data.frame(
x = rep(NA_real_, 100),
w = rep(1,100)
)
),
na.rm = TRUE
)
returns:
mean SE
x 0 0
Without the na.rm=TRUE
, the function returns NA:
survey::svymean(
~x,
design = survey::svydesign(
ids = ~1,
weights = ~w,
data = data.frame(
x = rep(NA_real_, 100),
w = rep(1,100)
)
)
)
returns:
mean SE
x NA NaN
Upvotes: 0
Views: 194
Reputation: 2765
Because that's what the code happens to return in this case and it wasn't thought to be worth adding a special case for the combination of no non-missing data and na.rm=TRUE
Upvotes: 1