Jorgen Harmse
2023-Nov-03 15:55 UTC
[R] I need to create new variables based on two numeric variables and one dichotomize conditional category variables.
df$LAP <- with(df, ifelse(G=='male', (WC-65)*TG, (WC-58)*TG)) That will do both calculations and merge the two vectors appropriately. It will use extra memory, but it should be much faster than a 'for' loop. Regards, Jorgen Harmse. ------------------------------ Message: 8 Date: Fri, 3 Nov 2023 11:10:49 +1030 From: "Md. Kamruzzaman" <mkzaman.m at gmail.com> To: r-help at r-project.org Subject: [R] I need to create new variables based on two numeric variables and one dichotomize conditional category variables. Message-ID: <CAGbxoeGjsxZKQ6qijEMq-X-5doqnQQS1jjPDDrGT6hH5xWqOKQ at mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hello Everyone, I have three variables: Waist circumference (WC), serum triglyceride (TG) level and gender. Waist circumference and serum triglyceride is numeric and gender (male and female) is categorical. From these three variables, I want to calculate the "Lipid Accumulation Product (LAP) Index". The equation to calculate LAP is different for male and females. I am giving both equations below. LAP for male = (WC-65)*TG LAP for female = (WC-58)*TG My question is 'how can I calculate the LAP and create a single new column? Your cooperation will be highly appreciated. Thanks in advance. With Regards *--------------------------------* *Md Kamruzzaman* *PhD **Research Fellow (**Medicine**)* Discipline of Medicine and Centre of Research Excellence in Translating Nutritional Science to Good Health Adelaide Medical School | Faculty of Health and Medical Sciences The University of Adelaide Adelaide SA 5005 [[alternative HTML version deleted]] [[alternative HTML version deleted]]
@vi@e@gross m@iii@g oii gm@ii@com
2023-Nov-03 21:11 UTC
[R] I need to create new variables based on two numeric variables and one dichotomize conditional category variables.
Just a minor point in the suggested solution: df$LAP <- with(df, ifelse(G=='male', (WC-65)*TG, (WC-58)*TG)) since WC and TG are not conditional, would this be a slight improvement? df$LAP <- with(df, TG*(WC - ifelse(G=='male', 65, 58))) -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Jorgen Harmse via R-help Sent: Friday, November 3, 2023 11:56 AM To: r-help at r-project.org; mkzaman.m at gmail.com Subject: Re: [R] I need to create new variables based on two numeric variables and one dichotomize conditional category variables. df$LAP <- with(df, ifelse(G=='male', (WC-65)*TG, (WC-58)*TG)) That will do both calculations and merge the two vectors appropriately. It will use extra memory, but it should be much faster than a 'for' loop. Regards, Jorgen Harmse. ------------------------------ Message: 8 Date: Fri, 3 Nov 2023 11:10:49 +1030 From: "Md. Kamruzzaman" <mkzaman.m at gmail.com> To: r-help at r-project.org Subject: [R] I need to create new variables based on two numeric variables and one dichotomize conditional category variables. Message-ID: <CAGbxoeGjsxZKQ6qijEMq-X-5doqnQQS1jjPDDrGT6hH5xWqOKQ at mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hello Everyone, I have three variables: Waist circumference (WC), serum triglyceride (TG) level and gender. Waist circumference and serum triglyceride is numeric and gender (male and female) is categorical. From these three variables, I want to calculate the "Lipid Accumulation Product (LAP) Index". The equation to calculate LAP is different for male and females. I am giving both equations below. LAP for male = (WC-65)*TG LAP for female = (WC-58)*TG My question is 'how can I calculate the LAP and create a single new column? Your cooperation will be highly appreciated. Thanks in advance. With Regards *--------------------------------* *Md Kamruzzaman* *PhD **Research Fellow (**Medicine**)* Discipline of Medicine and Centre of Research Excellence in Translating Nutritional Science to Good Health Adelaide Medical School | Faculty of Health and Medical Sciences The University of Adelaide Adelaide SA 5005 [[alternative HTML version deleted]] [[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.
Possibly Parallel Threads
- I need to create new variables based on two numeric variables and one dichotomize conditional category variables.
- [EXTERNAL] RE: I need to create new variables based on two numeric variables and one dichotomize conditional category variables.
- I need to create new variables based on two numeric variables and one dichotomize conditional category variables.
- I need to create new variables based on two numeric variables and one dichotomize conditional category variables.
- I need to create new variables based on two numeric variables and one dichotomize conditional category variables.