Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. a <- data.frame(geocode_selector = c("36005", "36047", "36061", "36081", "36085"), county_name = c("Bronx", "Kings", "New York", "Queens", "Richmond"))
  2. b <- data.frame(geocode = c("360050002001002", "360850323001019"), jobs = c("4", "204"))
  3.  
  4. b[, "county_name"] <- NA
  5. for (i in 1:nrow(b)) {
  6. for (j in 1:nrow(a)) {.
  7. if (grepl(data.a$geocode_selector[j], b$geocode[i]) == TRUE) {
  8. b$county_name[i] <- a$county_name[j]
  9. }
  10. }
  11. }
  12.  
  13. b$geocode_selector <- substr(b$geocode,1,5)
  14. b2 <- merge(b, a, all.x=TRUE) #by default it will merge on common column names
  15.  
  16. b2
  17. geocode_selector geocode jobs county_name
  18. 1 36005 360050002001002 4 Bronx
  19. 2 36085 360850323001019 204 Richmond
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement