If the column numbers of dataset1
and dataset2
are equal, you can write a for
loop as this:
pval = rep(0, ncol(dataset1))
for(i in 1:ncol(dataset1)){
pval[i] = t.test(dataset1[, i], dataset2[, i], na.action = na.omit)$p.value
}
Here, dataset1[, i]
means the i
th column and na.omit
will remove the NA
s and then perform the test.