[R] cut2 not binning interval endpoints correctly
Jim Holtman
jholtman at gmail.com
Tue Nov 26 01:45:16 CET 2013
FAQ 7.31
Sent from my iPad
On Nov 25, 2013, at 9:01, Maximilian Butler <maximilian.butler at gmail.com> wrote:
> Hi everyone,
>
> I am attempting to bin a vector of numbers between 0 and 1 into intervals
> of 0.001 but many values at the endpoints of the intervals are getting
> binned into the wrong interval. For example, the first 3 rows are binned
> incorrectly here:
>
> library(Hmisc)
> df=data.frame(x=c(0.308,0.422,0.174,0.04709))
> df$bucket=cut2(df$x,seq(0,1,0.001),oneval=FALSE)
> print(df)
> x bucket
> 1 0.30800 [0.307,0.308)
> 2 0.42200 [0.421,0.422)
> 3 0.17400 [0.173,0.174)
> 4 0.04709 [0.047,0.048)
>
> I have tried closing and reopening RStudio after clearing the workspace and
> reinstalling the Hmisc package. I am running R version 3.0.2 on Windows 7
> 64-bit. Thank you.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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