I am writing a simple R program to execute a t-test repeatedly on data
contained in a data frame. My data looks like this:
Category Value1 Value2
1 .5 .8
1 .3
Try:
foo - function(data, ...)
{
res - unlist(lapply(split(data, data$Category),
function(.x)t.test(.x$Value1, .x$Value2)$p.value))
test - merge(data, as.data.frame(res), by.x=Category, by.y = 0)
return(test)
}
x - data.frame(Category = rep(1:15, each = 10), Value1 = rnorm(150), Value2
=
Hi David,
Try this:
# Data set
set.seed(123)
Category=as.factor(rep(1:15,each=10))
Value1 = rnorm(150)
Value2= rnorm(150)
yourdata=data.frame(Category,Value1,Value2)
# Global function
TTEST=function(mydata){
# Internal function
tt=function(x,y) t.test(x,y)$p.value
# p-values
for(i in
3 matches
Mail list logo