Hi Jorge,
That is exactly what I wanted - I should have given a reasonable
number of observations (my set has *almost* all paired observations,
so it will still break with that approach unless I manicure the data
set). Is there a way to fail nicely on a single one of the tests
without the whole thing failing?
again, thanks for your help
Dan
On 25/03/2009, at 7:46 AM, Jorge Ivan Velez wrote:
> # Data
> set.seed(1)
> x<-sample(1:3,100,replace=TRUE)
> y<-sample(1:20,100,replace=TRUE)
> z<-rnorm(100)
> Data<-data.frame(x,y,z)
>
> # Observations for Type and Class
> with(Data, table(x,y))
>
>
> # Splitting the data by Class
> SD<-with(Data,split(Data,y))
>
> res<-lapply(SD, function(.data){
> # Type combinations by Class
> combs<-t(combn(sort(unique(.data[,1])),2))
>
> # Applying the t-test for them
> apply(combs,1, function(.r){
> x1<-.data[.data[,1]==.r[1],3] # select third column
> x2<-.data[.data[,1]==.r[2],3] # select third column
> tvalue<-t.test(x1,x2)
> res<-c(tvalue$statistic,tvalue$parameter,tvalue
> $p.value)
> names(res)<-c('stat','df','pvalue')
> res
> }
> )
> }
> )
>
> res
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.