Phoebe Lee
Phoebe Lee

Reputation: 13

How to apply t.test to several dataframes?

I try to generate t.test for 12 dataframes. I try to create a list by doing

MyList <- list(data1,data2,data3...,data12)

and use lapply to to the t.test. But it is not working. I really don't know what to write...:(

Upvotes: 1

Views: 71

Answers (1)

akrun
akrun

Reputation: 887831

We can use mget to get all the datasets into a list

 MyList <-  mget(ls(pattern = "^data\\d+"))

then loop over the list and apply t.test

lapply(MyList, function(x) t.test(x$yourcolumn1, x$yourcolumn2))

Make changes with the column name (assuming that the test is applied to the same columns - not clear)

Upvotes: 2

Related Questions