x<- c(62, 60, 63, 59, 63, 67, 71, 64, 65, 66, 68, 66, 71, 67, 68, 68, 56, 62, 60, 61, 63, 64, 63, 59)
grp1<- factor(rep(LETTERS[1:2], c(1,2)))
grp2<-rep(1:3)
dat <- data.frame(x,grp1,grp2)
aaa<-function(dset,var,group) {
if (length(levels(group))==2) {
ttest<-t.test(dset$var~dat$group)
}
else {
anova<-aov(var~group,data=dset)
}
}
How to store t or F value and P value in data frame bbb? I hope that results like: if choose ttest, bbb$stat=t-value,bbb$p<-p-value if choouse anova,bbb$stat=F-value,bbb$p<-p-value Thanks!