[R] Setting breaks to data more appropriately

ROLL Josh F JRoll at lcog.org
Tue Mar 23 22:23:02 CET 2010


David 
Thanks you for the guidance.  I am looking to drive the data into the intervals.  Problem now is that I have a few 0 values that are returning as NA (e.g -> (0.1,0.2] (0.1,0.2] (0.1,0.2] <NA>      (0,0.1]  )
This is causing issues when I try and use the brks to inform a clorepleth map.  I tried setting all na's to 0 but because the dataset is in factor form (I guess this is why) it wont allow me to do so. Thoughts about how to handle the zero values?  Thanks 
JR

-----Original Message-----
From: David Winsemius [mailto:dwinsemius at comcast.net] 
Sent: Monday, March 22, 2010 12:46 PM
To: ROLL Josh F
Cc: r-help at r-project.org
Subject: Re: [R] Setting breaks to data more appropriately


On Mar 22, 2010, at 1:49 PM, LCOG1 wrote:

>
> Basic question.  For the below data, i would like to but each of the 
> values in a bin that represents their value.  So the below would 
> hopefully put .1 in the 0-.1 bin, .2 in the .11-.2 bin and so forth.  
> The outlying values would then be put into and outer category 
> representing everything
> >1.  Im
> using the breaks to inform some code for making a clorepleth map that 
> represents probabilities, which in some cases IS greater than 1

... not if it's a quantile or a probability.

> and i need
> to identify those better.

Define "better".

> As my code stands now, my real data is put put into this form when 
> brks is called:
>
>        0%        10%        20%        30%        40%         
> 50%        60%
> 0.00000000 0.05054675 0.07787235 0.11235238 0.14424786 0.18089360 
> 0.21475990
>       70%        80%        90%       100%
> 0.26309899 0.30807771 0.39478573 0.67573483.
>
> But what i want is for the values to be placed in bins corresponding 
> to their value(0-.1, .11-.2, .21-.3 etc)
>
> Pct.SFD<-c(.1,.2,.3,.4,.5,.6,.7,.8,.9,1,2,3)
> brks <- quantile(Pct.SFD, )
>
> I think this is clear.

It's not. You need to decide whether you want the breaking to be driven by you or by the data. If you are doing the driving then use

cut(object, breaks=c(seq(0,1, by=0.1), Inf) , right=TRUE)

If the data is doing the driving then:

cut(object, breaks=quantile(object, probs= seq(0,1,1/10 ) ) ,
right=TRUE)

--
David.

> Thanks
> --
> View this message in context: 
> http://n4.nabble.com/Setting-breaks-to-data-more-appropriately-tp16780
> 19p1678019.html Sent from the R help mailing list archive at 
> Nabble.com.
>
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list