I am trying to compute the variance for a variable in my data frame, var(df$var) keeps returning NA or NaN however. the variable is the ratio between two original variables; FOODperINC = FOODexp / TOTALINC
var() of FOODexp and TOTALINC do return numbers.
I have searched and tried the following:
remove NA's from original variables and FOODperINC.
add 1 to TOTALING, to avoid dividing over 0
var(as.numeric()) / var(as.vector())
I do not quite understand why I can;t compute the variance. What am I doing wrong?
My code for reference:
df4 = df3[!is.na(df3$FOODTOT.x),]
df4 = df4[!is.na(df4$FINCAFTM.x),]
df4$FINCAFTM.x = df4$FINCAFTM.x +1
df4$INCperFOOD = df4$FOODTOT.x / df4$FINCAFTM.x
df3$SEAperINC.x = df3$SEAFOOD.x / df3$FINCAFTM.x
df3$FOODperINC.x = df3$FOODTOT.x / df3$FINCAFTM.x
var.test(df3$FOODperINC.x, df3$SEAperINC.x)
var(df4$FOODperINC.x)
var(df3$SEAperINC.x, na.rm=T)
var(as.numeric(df4$FOODperINC.x), na.rm=T)
which(is.null(df4$FOODperINC.x))
cov(df5$SEAperINC.x, df3$FOODperINC.x)
View(df4$FOODperINC.x)
brainfart;
df4$INCperFOOD != df4$FOODperINC
Thank you Ossan!
"INCperFOOD", "FOODperINC", "FOODperINC.x",), row.names = c(NA,
5L), class = "data.frame")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.