I have a large dataset and I am looking to run t.tests on sub-groupings of my data. I have had success with t.test on a broad scale:
t.test(Measurement~Group, data=df, paired="FALSE")
But I need to break my data down first by region, and then by time series, and then run a t.test on the pre and post measurement. (In my actual dataset, I have 12 Regions and 24 time series.. so to do it manually would be 288 tests!)
I'm sure there is a relatively simple loop or something I can apply but I am really struggling as a new coder.
Thanks so much in advance for any help!!
Here is some sample data:
Region <- c("A","A","B","B","C","C", "D", "D", "E","E")
TimeSeries<- c("1","2","1","2","1","2","1","2","1","2")
Measurement <- c("0.1", "9.7", "8.3", "2.0", "0.3", "1.2", "4.4", "6.9", "5.3","3.2")
Group<- c("Pre", "Post","Pre", "Post","Pre", "Post","Pre", "Post","Pre", "Post")
df <- data.frame(Region,TimeSeries,Measurement,Group)
I tried this:
df_list <- split(df, as.factor(df$Region))
.. and now I have a list, but not sure how to work with that in terms of further splitting by time series and then running the t.tests and having results in a new dataframe.
Ideal outcome would be analyzing my data and having a table like this:
Region TimeSeries p-value (other columns that come as test results..)
A 1 0.7 .....
A 2 0.002 .....
... and so on with a result for each region and timestep.