vendredi 13 novembre 2020

Perform several hypothesis test at the same time (r)

Imagine I want to assess the normality of several variables from a given dataset using the Shapiro-Wilk test.

In the example data, I also want to group by species.

data(iris)
library(dplyr)
library(purrr)

iris %>% 
  select(Sepal.Length, Sepal.Width)%>%
  group_by(iris$Species)%>%
  lapply(. , shapiro.test)

This gives me the error:

Error in FUN(X[[i]], ...) : is.numeric(x) is not TRUE

I guess this error happens because lapply is computing the three variables as objects to apply the test, instead of grouping by species, and since Species is not numeric, it´s unable to compute it.

Any help would be appreciate it.

Aucun commentaire:

Enregistrer un commentaire