user8384020
user8384020

Reputation: 11

How can I extract a column from all of the data frames in a sublist and use this data to run a Kruskal Wallis test?

When I do:

kruskal.test(sapply(list$`sublist`, "[", 14))

I am able to run the test on the 14th column of each data frame within the sublist.

However, I need to run this on over 1000 sublists, so individually writing it out isn't an option. Any suggestions how to access the 14th column of each of the data frames within each individual sublist to run a Kruskal Wallis test on the data from that sublist only?

Basically, I just need a way to loop through the sublists, but I am not sure how to do that.

Thanks for your help!

Upvotes: 1

Views: 57

Answers (1)

Onyambu
Onyambu

Reputation: 79338

Just add another *apply function before it:

 lapply(list function(i) kruskal.test(sapply(i, "[", 14)))

Upvotes: 1

Related Questions