0

I'm trying to do a T.test between two data sets..

This is 'Dataset1'

TIME        5    10      15      20      25
Specimen no.                        
1          15.2 30.5     41     12.5         16.2
2          13.1 16.2    12.5    Na       13.2
3          16.11 45.7   11.4    18.9    11.7
4          11.2  Na    9.11    20.7      19

And another 'Dataset2'

TIME        5   10        15      20    25

Specimen no.                        
1       11.8    34.8    14.2    19.9    23.4
2         NA    6.4     29.2    32.7    17.1
3       10.0    35.5    38.5    28.3    27.3
4       18.7    NA      11.5    14.6    18.9

I just want to compare each 5 second interval from dataset1 to dataset2 using a t.test. How do I get that list of p values

So far I only have this

t.test(dataset1[[2]],dataset2[[2]])$p.value...

Clearly this is wrong....coz I don't know how I can access certain columns from dataset1 and dataset2 ...I also have NA values that could get me error messages

Geller Bing
  • 15
  • 1
  • 5

1 Answers1

0

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 ith column and na.omit will remove the NAs and then perform the test.

cogitovita
  • 1,685
  • 1
  • 15
  • 15
  • Hi cogitovita, thanks for the answer, but for some reason I'm getting this error message: Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my))) stop("data are essentially constant") : missing value where TRUE/FALSE needed In addition: Warning messages: 1: In mean.default(x) : argument is not numeric or logical: returning NA 2: In mean.default(y) : argument is not numeric or logical: returning NA – Geller Bing Oct 06 '13 at 03:00