On Tue, Aug 7, 2012 at 8:05 AM, Dominic Roye <dominic.r...@gmail.com> wrote: > Hello everyone, > > > First i explain my aim. I would like to calculate the frecuency of > temperature (datos.mx1, columns 3-6) for each month with the thresholds of > table lf.med and lc.med. > > numero1 <- hist(subset(datos.mx1[,3], > datos.mx1$Mes==1),plot=FALSE,breaks=c(min(datos.mx1[,3]),lf.med[1,2],lc.med[1,2],max(datos.mx1[,3]))) > # First month and only the first weather station (column 3) > > I now have to apply the above command for all 12 months at all the weather > stations. I've been trying to get with a for-loop, but without success. > > How can i do it the best way?
I'd suggest the tapply() function. If you could use dput() to make a small reproducible example of your data, I'll help you set up the exact syntax, but I think it's something like this: tapply(datos.mx1, datos.mx1$Mes, function(x) hist(x[,3], plot = FALSE, breaks = c(min(x[,3], lf.med[1,2], lc.med[1,2], max(x[,3])))) Best, Michael > > After this command, i'm only interested in the part of $counts. I hope > someone can help me. Any help is greatly appreciated!!! Thank you, > everybody`!! > >> datos.mx1 > Fecha Mes Serra.da.Foladoira Santiago Sergude Rio.Do.Sol > 1 01.01.2006 1 4.1 14.4 9.3 5.7 > 2 02.01.2006 1 5.5 9.8 11.0 7.6 > 3 03.01.2006 1 9.9 13.0 12.7 9.9 > 4 04.01.2006 1 9.7 13.3 12.7 9.7 > 5 05.01.2006 1 10.2 12.2 13.1 8.0 > 6 06.01.2006 1 4.2 14.2 10.2 5.4 > 7 07.01.2006 1 1.0 6.9 3.2 3.2 > . > . > .......................etc. > >>lf.med > Mes Serra.da.Foladoira Santiago Sergude Rio.Do.Sol > 1 1 7.833702 8.811945 8.122162 7.899513 > 2 2 7.766978 8.592693 8.041483 7.887327 > 3 3 7.864609 8.861457 8.385405 8.080646 > 4 4 8.204098 8.986149 8.803744 8.438141 > 5 5 8.716766 9.317366 9.385637 8.977087 > 6 6 9.377651 9.874497 10.194340 9.686213 > 7 7 9.838470 10.055430 10.447219 9.991618 > 8 8 10.046204 10.099868 10.520872 10.098330 > 9 9 9.780911 10.038629 10.156048 9.851299 > 10 10 9.425308 9.779886 9.646881 9.496192 > 11 11 8.417168 9.346191 8.791033 8.549046 > 12 12 7.968706 8.795800 8.038208 8.017603 > >>lc.med > Mes Serra.da.Foladoira Santiago Sergude Rio.Do.Sol > 1 1 21.29353 26.62562 23.71784 22.04786 > 2 2 21.97787 27.07213 25.68340 23.39020 > 3 3 22.69749 27.42612 26.97889 24.33741 > 4 4 24.49683 29.21054 29.76726 26.59280 > 5 5 25.24233 29.83056 30.75132 27.28277 > 6 6 26.46742 30.70485 33.02328 28.77892 > 7 7 27.72731 30.24450 34.28162 29.97767 > 8 8 27.64356 30.84850 34.52161 30.00666 > 9 9 27.21998 31.18390 33.19776 29.54618 > 10 10 25.35830 28.83195 29.63192 26.42831 > 11 11 22.37895 26.38226 25.69239 23.47575 > 12 12 21.44064 26.09142 23.99676 22.26208 > > [[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.