I am using reshape2 package to shape my data and use it for t-test. For me it is easier to visualize the data in separate columns. I have three treatment combinations where "wat" is nested within "spp" and "ins" is nested within water. My demo table contains 3 response variable namely "tyr", "esc" and "esc_R". I would be interested in seeing how ins influence response -> "tyr" in "spp" -> Bl, with treatment "wat" -> High (just an example).
Here is my data: demo.data
## Use orderBy function to sort data
library(doBy)
demo <- orderBy(~spp+wat+ins, data = demo)
## Create an unique data frame for a specific variable
df.bl.ins.1 <- demo[demo$spp == "Bl", c(1:3, 4)]
df.bl.ins.2 <- df.bl.ins.1[df.bl.ins.1$wat == "High", ]
And then I am having trouble executing dcast function.
df.bl.ins.tmp <- dcast(df.bl.ins.2, spp + wat ~ ins, value.var = "tyr")
I have found interesting information in the following threads
- Dason's suggestion - which works really well with ToothGrowth demo dataset. Unfortunately, when the table has multiple treatments (more than 2) the solution did not remain simple. I agree with Maiasaura's suggestions that creating an unique variable is the key to this problem. However, I am having hard time understanding what function(x) does or how to use it in my table.
Any help in this regard is much appreciated.
In addition, if you have alternative suggestions to do t-test without manipulating the original data frame (demo), I will be excited to hear about it.
Thanks in advance.
Edit Here is what I am expecting, for "tyr". In the following format I desire to compare "No" vs. "Yes" using a t-test.
spp wat ins No Yes
Bl High No 0.3036 0.1987
Bl High No 0.2577 0.1112
Bl High No NA 0.199
Bl High No 0.3299 0.1886
Bl High No 0.3301 0.2332