Frage

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

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top