Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a <- data.frame(geocode_selector = c("36005", "36047", "36061", "36081", "36085"), county_name = c("Bronx", "Kings", "New York", "Queens", "Richmond"))
- b <- data.frame(geocode = c("360050002001002", "360850323001019"), jobs = c("4", "204"))
- b[, "county_name"] <- NA
- for (i in 1:nrow(b)) {
- for (j in 1:nrow(a)) {.
- if (grepl(data.a$geocode_selector[j], b$geocode[i]) == TRUE) {
- b$county_name[i] <- a$county_name[j]
- }
- }
- }
- b$geocode_selector <- substr(b$geocode,1,5)
- b2 <- merge(b, a, all.x=TRUE) #by default it will merge on common column names
- b2
- geocode_selector geocode jobs county_name
- 1 36005 360050002001002 4 Bronx
- 2 36085 360850323001019 204 Richmond
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement