[R] t-test for multiple variables
Simon Anders
anders at ebi.ac.uk
Sat Jul 19 12:16:42 CEST 2008
Hi Henning,
Henning Wildhagen wrote:
> i tried your code, but it results in an error:
>
> "error in var(x) : `x` is empty"
>
> Do you have an idea what the reason might be?
If you ask questions on this list, please provide some code snippets,
which the others can copy and paste to reproduce your error. Otherwise,
we can only guess, so post the commands that you entered before my
command, and also, how you modified my command to suit your variable names.
Here is my example again, now complete with sample data:
> df <- data.frame(
+ a = factor( sample( c("A","B","C"), 20, replace=TRUE ) ),
+ b = runif( 20 ),
+ c = runif( 20 ) )
> df
a b c
1 B 0.49008816 0.03863320
2 B 0.14562516 0.22690694
3 B 0.66213412 0.17329673
4 C 0.86378488 0.78466689
5 C 0.40586715 0.94727504
6 A 0.46095342 0.94411009
7 A 0.02613032 0.07600194
[...]
> tapply( 1:nrow(df), df$a, function(r)
+ t.test( df$b[r], df$c[r], paired=TRUE ) )
cu
Simon
More information about the R-help
mailing list