[R] Help with the Cut Function
David Winsemius
dwinsemius at comcast.net
Sat Jun 25 23:55:00 CEST 2016
> On Jun 25, 2016, at 12:05 PM, Shivi Bhatia <shivipmp82 at gmail.com> wrote:
>
> Dear Team,
>
> Please see the code below:
>
> Age1<- cut(desc$Age, breaks = c(20,30,40,Inf),labels = c("Low","Mid","Top"))
Try instead:
Age1<- cut(desc$Age, breaks = c(-Inf, 20,30,40,Inf),labels = c("Low","Mid","Top"))
Do note that values that are <= 20 will be in the lowest category. (You wrote only <20 whereas values of 20 would have not been in any interval.) The cut function also has a use.lowest argument, whose actions I don't fully understand but I usually set to to TRUE whereas is default is FALSE. I prefer the Hmisc::cut2 functions because its defaults mirror my usual interests. Like cut2, the findInterval function has closed intervals on the left.
> here i am creating three categories as mentioned from the age var from desc
> data set.
> All the values are set correctly however the values which are below 20 are
> set to NA.
> Is there anything i am doing incorrect.
>
> Regards, Shivi
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list