I want to create a categorical variable for my DB: I want to create the "Same_Region" group, that includes all the people that live and work in the same Region and a "Diff_Region" for those who don't. I tried to use the IF statement, but I actually don't know how to proper say "if the variable Region of residence and Region of work are the same, return...". It's the very first time I try to approach by my self R, and I feel a lil bit lost.
I tried to put the two variables (Made by 2 letters - f.i. "BO") as Characters and use the "grep" command. But it eventually took to no results. Then I tried by putting both the variables as factors, and nothing much changed.
----In R-----
extractSamepr <-function(RegionOfRes, RegionOfWo){if(RegionOfRes== RegionOfWo){return("SamePr")} else {return("DiffPr")}
SamePr <- NULL for (i in 1:nrow(Data.Base)) {SamePr<- c(SamePr, extractSamepr(Data.Base[i,"RegionOfRes","RegionOfWo"]))}
Aucun commentaire:
Enregistrer un commentaire