Open anniewest opened 5 years ago
Hi,
You forgot to extract only the p.value when applying your if condition :
shapiro.test(rich$alpha_diversity[["Chao1"]]
Shapiro-Wilk normality test data: rich$alpha_diversity[["Chao1"]] W = 0.92967, p-value = 0.02189shapiro.test(rich$alpha_diversity[["Chao1"]])$p.value [1] 0.0218892
you should try this :
rich_psR <- estimate_richness(psR, measures = c("Chao1","Shannon", "InvSimpson")) rich <- list(rich_psR, sample_data(psR)$SampleID, sample_data(psR)$Location) names(rich) <- c("alpha_diversity", "SampleID", "Location")
if (shapiro.test(rich$alpha_diversity[["Chao1"]])$p.value > 0.05) {print(aov(rich$alpha_diversity[["Chao1"]], rich$Location))} else {print(kruskal.test(rich$alpha_diversity$Chao1, rich$Location))}
shapiro.test(rich$alpha_diversity[["Chao1"]])$p.value
Hi @FelixGiraud,
Thanks for your tip on extracting the p-value, but the code still had the same atomic vector error.
I managed to get it working with this though:
if (shapiro.test(rich$alpha_diversity[["Chao1"]])$p.value > 0.05) {print(aov(rich$alpha_diversity[["Chao1"]]~rich$Location, data = rich))} else {print(kruskal.test(rich$alpha_diversity$Chao1, rich$Location))}
Hey everyone,
I'm trying to write an if else loop (as below) and I keep coming up with the error $ operator is invalid for atomic vectors Even when I try to have the item as a list or dataframe the variable with characters still comes up as an atomic vector? Is it because I have taken it straight from the sample_data(psR)?
`rich_psR <- estimate_richness(psR, measures = c("Chao1","Shannon", "InvSimpson")) rich <- list(rich_psR, sample_data(psR)$SampleID, sample_data(psR)$Location) names(rich) <- c("alpha_diversity", "SampleID", "Location")
if (shapiro.test(rich$alpha_diversity$Chao1) > 0.05) {print(aov(rich$alpha_diversity$Chao1, rich$Location))} else {print(kruskal.test(rich$alpha_diversity$Chao1, rich$Location))}`
When I check the structure of the object, my Location variable is a factor with 8 levels, as is my SampleID variable but with 57 levels.