Petr Pikal petr.pi...@precheza.cz 724008364, 581252140, 581252257
r-help-boun...@r-project.org napsal dne 26.06.2009 05:31:27: > Hi all, > > This is a really basic question but I can't figure it out. > > I am trying to write a piece of code that will use two datasets, z and m.. > This code is meant to assign the mean of selected values in dataset m to a new > column z$c in datset z but the rows and columns of the two data sets differ. > > I managed to write this down but think I am missing something standard but > basic,I will really appreciate if someone could point out where I' am going > wrong or help me out with a piece of code for this.Google did not help me even > and the R manuals gave me hints. > > "The shoulders will never grow beyond the head". > > for (k in 1:nrow(z)) > + for (g in 1:nrow(m)) > + for (l in 1:3) > + for (j in 15:43){ > + z$ccs[k]<-mean(m[m$soi[g]==l&m$week[g]==j,]$CCS,na.rm=TRUE)} Maybe that I have no idea what is z I get an error too. > for (k in 1:nrow(z)) + + for (g in 1:nrow(m)) + + for (l in 1:3) + + for (j in 15:43){ + + z$ccs[k]<-mean(m[m$soi[g]==l&m$week[g]==j,]$CCS,na.rm=TRUE)} Error in nrow(z) : object 'z' not found What kind of error do you have? If you do not post some reproducible example it would be quite difficult to understand what you want to get as a result. I believe some *apply trick could help but without knowing what you want it could be just rough guessing. Regards Petr > > > > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. ______________________________________________ R-help@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.