[R] Create a categorical variable using the deciles of data
Richard O'Keefe
r@oknz @end|ng |rom gm@||@com
Thu Jun 16 04:36:28 CEST 2022
I had the advantage of studying
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
"The New S Language". Wadsworth & Brooks/Cole.
before starting to use R. That book was reissued by CRC Press
only a few years ago. It's *still* a pretty darned good intro
to R. cut, pretty, and quantile are all there. They are
pretty basic.
I strongly recommend looking for a copy of that book and
skimming through appendix 1 repeatedly until you have a rough
idea of what's there. A lot has been added since then, and R
never did srarch the current working directory as part of the
environment, but a lot has NOT changed. category(..) has gone,
that's the main difference I recall.
On Wed, 15 Jun 2022 at 01:49, Ebert,Timothy Aaron <tebert using ufl.edu> wrote:
> A problem in R is that there are several dozen ways to do any of these
> basic activities. I used the approach that I could get to work the fastest
> and tried to make it somewhat general. I do not know functions like ?pretty
> that Rui used, nor ?quantile or ?cut. It is a difficulty in learning R
> where the internet or sites like this one are the "teacher." There are
> plenty of books, but they too take one approach to solve a problem rather
> than "here is a problem" and "these are all possible solutions." I
> appreciate seeing alternative solutions.
>
> Tim
>
> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Richard O'Keefe
> Sent: Tuesday, June 14, 2022 9:08 AM
> To: anteneh asmare <hanatezera using gmail.com>
> Cc: R Project Help <r-help using r-project.org>
> Subject: Re: [R] Create a categorical variable using the deciles of data
>
> [External Email]
>
> Can you explain why you are not using
> ?quantile
> to find the deciles then
> ?cut
> to construct the factor?
> What have I misunderstood?
>
> On Tue, 14 Jun 2022 at 23:29, anteneh asmare <hanatezera using gmail.com> wrote:
>
> > I want Create a categorical variable using the deciles of the
> > following data frame to divide the individuals into 10 groups equally.
> > I try the following codes
> > data_catigocal<-data.frame(c(1:50000))
> > # create categorical vector using deciles group_vector <-
> >
> > c('0-10','11-20','21-30','31-40','41-50','51-60','61-70','71-80','81-9
> > 0','91-100') # Add categorical variable to the data_catigocal
> > data_catigocal$decile <- factor(group_vector) # print data frame
> > data_catigocal
> >
> > can any one help me with the r code
> > Kind regards,
> > Hana
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mail
> > man_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAs
> > Rzsn7AkP-g&m=JNEsCwSpVwVmoMiEXA8K7ZWqg1GZK3Cx87LshtZ5gy5Y8SyDZrUSTuotO
> > cQ44yzy&s=2x4gMg5K_GJPK-XUk3UfSB3hhFCziCOgqvxl7yJXTvA&e=
> > PLEASE do read the posting guide
> > https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.or
> > g_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeA
> > sRzsn7AkP-g&m=JNEsCwSpVwVmoMiEXA8K7ZWqg1GZK3Cx87LshtZ5gy5Y8SyDZrUSTuot
> > OcQ44yzy&s=50k59quZy2KmFsVBRxK4P-M7RyxDsPGieX6TiiY5or0&e=
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=JNEsCwSpVwVmoMiEXA8K7ZWqg1GZK3Cx87LshtZ5gy5Y8SyDZrUSTuotOcQ44yzy&s=2x4gMg5K_GJPK-XUk3UfSB3hhFCziCOgqvxl7yJXTvA&e=
> PLEASE do read the posting guide
> https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=JNEsCwSpVwVmoMiEXA8K7ZWqg1GZK3Cx87LshtZ5gy5Y8SyDZrUSTuotOcQ44yzy&s=50k59quZy2KmFsVBRxK4P-M7RyxDsPGieX6TiiY5or0&e=
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list