Richard O'Keefe
2022-Jun-14 13:07 UTC
[R] Create a categorical variable using the deciles of data
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 at 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-90','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 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. >[[alternative HTML version deleted]]
Ebert,Timothy Aaron
2022-Jun-14 13:49 UTC
[R] Create a categorical variable using the deciles of data
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 at r-project.org> On Behalf Of Richard O'Keefe Sent: Tuesday, June 14, 2022 9:08 AM To: anteneh asmare <hanatezera at gmail.com> Cc: R Project Help <r-help at 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 at 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 at 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 at 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&ePLEASE 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&eand provide commented, minimal, self-contained, reproducible code.