[R] R Help finding Mean
jim holtman
jholtman at gmail.com
Thu Sep 1 15:55:55 CEST 2011
If you format it a little differently, it is easier to read:
bob<-read.csv('shi.csv', header=T)
newmean<-matrix(0, test, dim(bob)[2]-6)
a<-0
for (i in c(4,8:(dim(bob)[2]))){
a<-a+1
newmean[,a]<-tapply(bob[,i], bob$Exam, mean)
}
colnames(newmean)<-colnames(bob)[c(4,8:(dim(bob)[2]))]
It looks like it is computing the means of columns 4, then 8 through
the last one, but since we don't know what 'shi.csv' is, it is hard to
tell. You might have problems in the assignment to 'newmean'
depending on if the length of the result of tapply is equal to the
number of rows. It appears that each row should be an Exam. The are
other approaches (data.table, plyr) that might be applicable, but you
need to following the posting guidelines.
On Thu, Sep 1, 2011 at 8:36 AM, cenae27 <cenae27 at hotmail.com> wrote:
> bob<-read.csv('shi.csv', header=T)
>
> newmean<-matrix(0, test, dim(bob)[2]-6);a<-0; for (i in
> c(4,8:(dim(bob)[2])))
> {a<-a+1;newmean[,a]<-tapply(bob[,i], bob$Exam, mean)}
> colnames(newmean)<-colnames(bob)[c(4,8:(dim(bob)[2]))]
>
> Could anyone please help me what does the above code does ... I want to find
> mean ... but would like to know what exactly is the above code doing.
>
> Thanks for your help.
> Cenae
>
> --
> View this message in context: http://r.789695.n4.nabble.com/R-Help-finding-Mean-tp3783400p3783400.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
More information about the R-help
mailing list