First time posting here!
I'm having difficulty trying to mix the two dataset to calculate t.test:
library('tidyverse')
set.seed(123)
x <- data.frame( compounds=c( "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"),
sample1=sample( 1:6, replace=T, 10),
sample2=sample( 1:10, replace = T, 10),
sample3=sample( 1:10, replace = T, 10),
sample4=sample( 1:10, replace = T, 10),
sample5=sample( 1:10, replace = T, 10))
y <- data.frame( group1=sample( c(0,1), replace=T, 5),
group2=sample( c(0,1), replace=T, 5),
group3=sample( c(0,1), replace=T, 5))
rownames(y) <- c( "sample1", "sample2", "sample3", "sample4", "sample5")
> x
compounds sample1 sample2 sample3 sample4 sample5
1 a 3 6 10 7 2
2 b 6 9 7 9 5
3 c 3 10 10 9 8
4 d 2 5 9 10 2
5 e 2 3 3 7 1
6 f 6 9 4 5 9
7 g 3 9 1 7 9
8 h 5 9 7 5 6
9 i 4 3 5 6 5
10 j 6 8 10 9 9
> y
group1 group2 group3
sample1 0 1 1
sample2 1 1 1
sample3 1 1 0
sample4 0 0 0
sample5 1 1 1
I want to calculate t.test with the numerical values in "x".
The grouping for t.test(a, b) are defined in "y" by 0 and 1.
For each grouping in "y" I want to calculate t.test for all compounds "a" to "j".
The column names in "x" are rownames in "y"
I can do this in a very lengthy way using forloops, but would love your help in doing this with tidyverse
Thank you!!!