I have a data frame df in R with categorical variables: column names of the variables are 'A', 'B', 'C' and another categorical variable is 'gene'
I want to run pairwise fisher exact test in R. When I run it one by one like this:
A <- xtabs(~ A + gene, data = df)
pairwise_fisher_test(A ,p.adjust.method = 'fdr')
B <- xtabs(~ B + gene, data = df)
pairwise_fisher_test(B ,p.adjust.method = 'fdr')
C <- xtabs(~ C + gene, data = df)
pairwise_fisher_test(C ,p.adjust.method = 'fdr')
this works!!!
Now I am trying to use lapply like this:
vec <- ('A','B','C')
lapply(vec,function(x){
xtabs(~ x + gene, data = df)
pairwise_fisher_test(xtabs(~ x + gene, data = df) , p.adjust.method = 'fdr')
})
I get this error:
Error in model.frame.default(formula = ~x + gene, data = df): variable lengths differ (found for 'gene')
What am I doing wrong??