I have been getting error messages when trying to do hypothesis tests, like T or Wilcox tests, on nested data. This is all code that previously worked until recently. (I wonder if it could be related to the dplyr .7 update?) For example,
ID <- 1:100
group <- as.character(rep(c('w', 'x', 'y', 'z'),25))
factor <- as.factor(rep(c('a', 'b'), 50))
num <- runif(100)
df<- data.frame(ID, group, factor, num)
dfTtest <- df %>%
nest(-group) %>%
mutate(p = map_dbl(data, ~t.test(.$num~.$factor)$p.value))
Gives me the error:
Error in mutate_impl(.data, dots) :
Evaluation error: invalid type (NULL) for variable '.$num'.
In addition: Warning messages:
1: Unknown or uninitialised column: 'num'.
2: Unknown or uninitialised column: 'factor'.
How can I fix this?
Thank you!