[R] Vector Manipulation

Bill.Venables@cmis.csiro.au Bill.Venables at cmis.csiro.au
Mon Jul 22 06:14:08 CEST 2002


Bill Vedder asks and Marc Schwartz offers a reply:

>  -----Original Message-----
> From: 	Marc Schwartz [mailto:mschwartz at medanalytics.com] 
> Sent:	Monday, July 22, 2002 12:26 PM
> To:	wvedder at houston.rr.com; r-help at stat.math.ethz.ch
> Subject:	Re: [R] Vector Manipulation
> 
> > Greetings,
> > 
> > 
> > I wonder if someone could point me towards a more elegent solution
> than
> > what I"ve kluged together. I have a vector "samp1" of 296 integers.
> > They are sorted in ascending order and the numbers range from 177 to
> > 228,953. I'd like to specify N non-overlapping intervals covering the
> > range from 0 to 229,354 and then for each range, count the number of
> > integers from samp1 that fall into that range. What I'll end up with
> is
> > an N element vector with each element representing the number of
> > integers from samp1 found in the Nth range.
> > 		
> > 
> > Can someone point me to a function / procedure that allows me to
> specify
> > 
> > the non-overalpping intervals? and also one that I can use to do the
> > counting?
> > 
> > 
> > Best,
> > Bill Vedder
> 
> Bill,
> 
> Take a look at ?cut and ?hist.  With hist(), look at the values returned
> when "plot = FALSE".
> 
> HTH.
> 
> Marc
> 
	[WNV]  Let me offer a different possibility, if only mildly
different.

	cut( ) will take the break points and form a factor from your vector
and table( ) will do the counting.  This is a pretty standard problem, in
fact.  

Bill Venables, 
CMIS, CSIRO Marine Laboratories, 
PO Box 120, Cleveland, Qld. 4163
AUSTRALIA
Phone:  +61 7 3826 7251  
Fax:    +61 7 3826 7304
Mobile: +61 419 634 642
<mailto: Bill.Venables at csiro.au>
http://www.cmis.csiro.au/bill.venables/

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list