Assign labels with an 'if'

Hi-I'm assigning labels to Regions for two countries; I need to update the below
'OtherNeighboring_CountrySSD' to only be for SSD, and the 'OtherNeighboring_DRC' to only be for DRC. Country is the variable specifying SSD or DRC.

North_America <- c("Canada", "USA")
### GHHelp: Update the below to only be for SSD. 
OtherNeighboring_CountrySSD <- c("Sudan", "Uganda", "Ethiopia", "Central African Republic")
#GHHelp: Update the below to only be for DRC 
OtherNeighboring_CountryDRC <- c("Congo", "Central African Republic", "Uganda", "Rwanda", "Burundi", "Tanzania")
Middle_East <- c("Syria")
Europe <-c("United Kingdom")
Asia <- c("Bangladesh", "China", "India", "Indonesia", "Malaysia", "Pakistan")
Other_Africa <- c("Egypt", "Eritrea", "Malawi", "Mauritius", "Nigeria", "Zambia", "Zimbabwe")
South_Sudan <-c("South Sudan")
DRC <-c("DRC")

df_enrollment_clean$Region[nationality %in% North_America] <- "North America"
#Update to only be for SSD 
df_enrollment_clean$Region[nationality %in% OtherNeighboring_CountrySSD] <- "Other neighboring country, SSD"
#Update to only be for DRC. 
df_enrollment_clean$Region[nationality %in% OtherNeighboring_CountryDRC] <- "Other neighboring country, DRC"
df_enrollment_clean$Region[nationality %in% Middle_East] <- "Middle East"
df_enrollment_clean$Region[nationality %in% Europe] <- "Europe"
df_enrollment_clean$Region[nationality %in% Asia] <- "Asia"
df_enrollment_clean$Region[nationality %in% Other_Africa] <- "Africa, non-neighboring country"
df_enrollment_clean$Region[nationality %in% South_Sudan] <- "South Sudan"
df_enrollment_clean$Region[nationality %in% DRC] <- "DRC"

#GH Help 
table1(~Region | country, data=df_enrollment_clean, total=F)

What does df_enrollment_clean look like?

Can you post an example? e.g dput(head(df_enrollment_clean))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.