fantastic Michael! The code "V = sort(unique(ave(x,cut(x,HistOut$breaks))))" works good. I got what I need! that is 20 mean values. I calculate the first value in excel, it's the same (79.61429).
> HistOut= hist(data$ DMP_m3.jaso..10, freq=F, breaks =20, > xlim=c(0,3000),col="grey26", main="DMP_niger", plot=T) V = sort(unique(ave(data$ DMP_m3.jaso..10,cut(data$ DMP_m3.jaso..10,HistOut$breaks)))) > write(V, "", sep = " ") 79.61429 149.9792 257.4969 347.8211 449.2063 552.9694 647.5132 749.23 859.0167 945.4912 1046.917 1147.703 1249.375 1359.794 1447.518 1553.838 1649.231 1735.217 1850.617 1957.85 2031.329 2156.8 2247.55 2340.6 2822.1 Thank you very much. francesco From: michael.weyla...@gmail.com Date: Tue, 23 Aug 2011 11:27:13 -0400 Subject: Re: [R] [r] histogram with mean for every break To: nutini.france...@gmail.com CC: r-help@r-project.org I do not believe your code (minimal as it is) would work: the correct argument is "breaks". More generally, do you really mean to say that hist(x, breaks = 20) immediately returns the bin counts? It doesn't on my machine and if you knew how to get the counts, you should be able to get the midpoints as well. Try this x = rnorm(5000) HistOut = hist(x, breaks = 20) HistOut$mids # will give midpoints for each bin of this histogram If you need proper means, rather than midpoints: # I *think* this works -- no guarantees: it assigns x to bins based on the histogram breaks, averages those by bin, and then we pull out just the unique values and sort them V = sort(unique(ave(x,cut(x,HistOut$breaks)))) It does seem to be a somewhat strange task to use histogram breaks to get means though: if I were you, I'd spend a minute or two contemplating if this really makes the most sense, rather than just doing the breaks in some way yourself directly. There may well be a more elegant way but I think this gets the job done. Hope it helps, Michael On Tue, Aug 23, 2011 at 9:46 AM, Francesco Nutini <nutini.france...@gmail.com> wrote: Dear R-users, I need to produce a histogram where for every breaks there are the mean of the data. I tried tu use the function >hist(x, break=20 ... ) but this return the numerosity for every breaks, not the mean. Any hint? Thanks in advance, francesco --------------------------------------- Francesco Nutini CNR-IREA Ist. per il Rilevamento Elettromagnetico dell'Ambiente Via Bassini 15, 20133 Milano (Italy) Tel: +39-02 23699 297 http://www.irea.cnr.it nutin...@irea.cnr.it Skype: ui...@hotmail.it Univ. mail: francesco.nut...@unimi.it --------------------------------------- [[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. [[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.