Could someone show me the codes for grouping a continuous variable as a categorical variable? for instance, BMI in my dataset is a continuous variable, if I want to redefine the variable in a new variable bmigp as
bmigp = 1 if bmi<25
bmigp= 2 if 25<= bmi< 30
bmigp= 3 if bmi>=30
Thanks Leon. it works. BTW, I found another way that does the same job before seeing yours. ie,
mutate(bmigp=cut(bmi, c(0, 25, 30, 40), labels=c("nwt", "owt", "obese"), LEFT =FALSE)))
Hi Leon,
Thanks for your kindness help. I'm a SAS user and try to learn R now. I know how to do data merge in SAS, but have trouble doing so in R. I have two datasets A and B, they have a variable ID that can be used for merging. I try to add information of 3 variables from data B, ie, x, y, and z to data A. what should be the codes? I appreciate your help in advance.
Jason
You'll need to put in some effort, but your R-journey will be well worth it. What you're asking about is called Relational Data and I would recommend going through the corresponding chapter in R for Data Science. Moreover, if you really want to get into modern R - I HIGHLY recommend you going through R4DS back-to-back