I am not sure what is wrong with this script. I get the following error message "Error in if (is.na(MOE)) { : the condition has length > 1"
See the snippet below:
z_score_val <- function(GEOID, X1, MOE) {
if (is.na(MOE)) {
0
}
else {
SE1 <- (MOE/1.645)
sqrM <- (MOE^2)
SE2 <- sqrt(sum(sqrM,na.rm = TRUE))/1.645
X2 <- mean(X1,na.rm = TRUE)
message(X2, ' this is the mean X2')
message(SE2, ' this is SE2')
sign_test <- abs((X1-X2))/sqrt(SE1^2 + SE2^2)
my_list <- list(GEOID, MOE, SE1,sqrM, sign_test)
return(my_list)
}
#return(sign_test)
}
I am not sure what else can be wrong