Dear Team,
Please see the code below:
Age1<- cut(desc$Age, breaks = c(20,30,40,Inf),labels =
c("Low","Mid","Top"))
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]]
On 26/06/16 07:05, Shivi Bhatia wrote:> Dear Team, > > Please see the code below: > > Age1<- cut(desc$Age, breaks = c(20,30,40,Inf),labels = c("Low","Mid","Top")) > 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.No. What is the problem? This seems to me to be exactly what one would expect. If you don't want NAs, set your lower break to be less than the minimum of desc$Age, e.g. -Inf. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
> 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
Hi David,
I tried as suggested however with this code:
Age11<- cut(desc$Age, breaks = c(-Inf, 20,30,40,Inf),labels
c("Low","Mid","Top")) i receive an error message
as below:
lengths of 'breaks' and 'labels' differ. Now as a result i have
values
exceeding 40 as N/A.
On Sun, Jun 26, 2016 at 3:25 AM, David Winsemius <dwinsemius at
comcast.net>
wrote:
>
> > 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
>
>
[[alternative HTML version deleted]]