[R] How to creat a dummy coding in R? (URGENT!)

Jim Lemon jim at bitwrit.com.au
Wed Mar 26 08:16:17 CET 2014


On 03/26/2014 05:35 AM, Si Qi L. wrote:
> Hi, it's so urgent that I really need your help on R. This following is
> part of my data, do u know how to create a dummy coding about it in R? My
> control group is Owner occupier. Many thanks for your big help!!!:)
>
> *AppHomeStatus*
> Owner occupier
> Living with parents
> Living with parents
> Private tenant
> Private tenant
> Private tenant
> Council tenant
> Owner occupier
> Owner occupier
> Living with friends/family

Hi Si Qi,
the above doesn't make a lot of sense, but I'll guess that you want to 
convert your AppHomeStatus variable to a factor with "Owner occupier" as 
the first level. Assume that the data frame is named "mydata".

mydata$AppHomeStatus<-factor(mydata$AppHomeStatus,
  levels=c("Owner occupier","Living with parents",
  "Private tenant", "Living with friends/family"))

If you have more levels, make sure that you add them to the "levels" 
argument.

Jim




More information about the R-help mailing list