回复 第2楼 的 波波头一头:
楼主能不能在帮我看看我的程序有什么问题,我得出来的只有一种结果,好奇怪,但我找不到错在哪
a b c
1 10 5
1 10 5
1 10 5
1 10 5
1 10 NA
1 10 5
1 10 5
1 10 5
1 10 5
1 10 5
2 10 5
2 10 5
2 10 5
2 10 5
2 10 NA
2 10 5
2 10 5
2 10 5
2 10 5
2 10 6
程序
x<-1;i<-1;
while(x+1<3){
x[i+1]<-x+1
i<-i+1
}
f1<-function(x){
df<-array(0,dim=c(2,3))
newdata<-subset(data,data$a==x)
df[x,1]<-sum(!is.na(newdata$c))
df[x,2]<-mean(newdata$c,na.rm=T)
df[x,3]<-sd(newdata$c,na.rm=T)
write.csv(df,file="result.csv")
}
f1(x)