メモ

area <- 1:10
age <- 11:20
val <- 21:30
x <- data.frame(list(area=area,age=age,val=val))
x
x$agen <- as.factor(ifelse(x$age<=15,"lo","hi"))
x
t.out <- t.test(x$val~x$agen)
t.out$p.value

#関数化
nmeansd <- function(X,C) {
cat("N=",length(X[C]),"\t mean=",mean(X[C]),"\t sd=",sd(X[C]),"\n") }
#関数化2(他の関数などに渡す)
nmeansd <- function(X,C) {
list(n=length(X[C]),mean=mean(X[C]),sd=sd(X[C])) }

#for文で繰り返したい
> length(levels(x$agen))
[1] 2
> cmeansd(x$val,x$agen==levels(x$agen)[1])
> cmeansd(x$val,x$agen==levels(x$agen)[2])