[R] problem with rbind
SNN
s.nancy1 at yahoo.com
Wed Jan 21 06:07:40 CET 2009
Hi All,
I have a problem with rbind.
I have data that consist of weight height .. etc of 1000 patients. I would
like to find the mean and the standard deviation ( for the weight , height
etc) for each gender.
data<-read.table("data.txt", header=T, sep='\t')
fdata=NULL
for (i in 1:50){
nn<-names(X)[i]
m<-tapply(X[,i],data$gender,mean,na.rm=T)
s<-tapply(X[,i], data$gender, sd,na.rm=T)
p<-cbind(mean=m,sd.dev=s)
cn<-paste(nn,colnames(p),sep="_")
colnames(p)<-cn
fdata<-rbind(fdata,p)
}
write.table(fdata, “results.txt”,sep=’\t’,quote=FALSE, col.names=T)
here is the problem,
1. I have a header for each table but only the first one is printed.
2. the weight_mean is suppose to be on the top of the means but it appears
on the top of the first column ( with no tab before the header)
weight_mean weight_sd.dev
F 14.33333 4.932883
M 34.66667 10.692677
F 35.00000 7.071068
M 34.66667 10.692677
.
.
.
I want the result to look like this with a line separating each table and
each table has a header
weight_mean weight_sd.dev
F 14.33333 4.932883
M 34.66667 10.692677
hight_mean hight_sd.dev
F 35.00000 7.071068
M 34.66667 10.692677
3.Is there a way to make a title for each table, for example
weight
weight_mean weight_sd.dev
F 14.33333 4.932883
M 34.66667 10.692677
I appreciate your help,
--
View this message in context: http://www.nabble.com/problem-with-rbind-tp21577241p21577241.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list