A fast way to get **only** means of successive bins of width k of a
vector z of length nk is:

m <- colMeans(matrix(z,nrow = k))

(you wanted k =50)
This was instantaneous for a length 1e6 numeric vector on my laptop.

However, for anything else, you have to use something like cut() as
others have previously advised.

-- Bert

On Mon, Nov 21, 2011 at 10:08 PM, Joshua Wiley <jwiley.ps...@gmail.com> wrote:
> Hi Jeffrey,
>
> See ?factor ?rep and ?cut  basically you just need to create another
> variable that indicates what bin a point belongs to, and then you just
> do regular plots.  If you want to mix the scatterplot and the binned
> points, you'll need to make sure the bins fall somehwere in the same
> space.  Once you have a variable indicating the bins.  You could
> center the bins at the mean, median, or ... for each set of points
> using ?ave.
>
> Cheers,
>
> Josh
>
> On Mon, Nov 21, 2011 at 9:29 PM, Jeffrey Joh <johjeff...@hotmail.com> wrote:
>>
>> I have a scatter plot with 10000 points.  I would like to add a line that 
>> bins every 50 points and connects the average of each bin.  I'm looking for 
>> something similar to line type "m" in Stata.
>>
>> With this dataset of 10000 points, I would also like to bin the data and 
>> make boxplots at certain intervals, so that I have a set of boxplots to 
>> represent each bin.  I would also like the width of each box to be 
>> proportional to the number of points in each bin.
>>
>> How can I make these plots?  Is there a simple package to use?
>>
>> Jeffrey
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> Joshua Wiley
> Ph.D. Student, Health Psychology
> Programmer Analyst II, ATS Statistical Consulting Group
> University of California, Los Angeles
> https://joshuawiley.com/
>
> ______________________________________________
> 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.
>



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

______________________________________________
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.

Reply via email to