I am using this data.frame. I need to apply statistical tests (wilcox.test) for each column by comparing the '0' to the '1' groups, but I can only do that if each group has at least 2 values. How can I remove all columns for which the group size of '0' or the group size of '1' is smaller than 2? Then I can be running my code without errors. So in this example the pear and cherry columns would be removed.
df <- data.frame(group=c(rep(0,10),rep(1,10)),
apple = as.numeric(c(runif(20, -1, 18))),
pear = as.numeric(c(rep("NA",12), runif(8, 2, 7))),
banana = as.numeric(c(runif(10, 1, 3), runif(10, 2.5, 6))),
cherry = as.numeric(c(runif(9, 5, 12), rep("NA",10), 4.31)),
kiwi = as.numeric(c(rep("NA",8), runif(12, -1, 6))))