Created
May 14, 2016 00:11
-
-
Save MattSandy/20e43153a7e656bab549de6247639081 to your computer and use it in GitHub Desktop.
Create Column that Mark Rows as Matched between Two Datasets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pop <- read.csv(paste("~/R/dumb_shit/import/","pop.csv",sep=""), header = FALSE, sep = ",", quote = "\"",stringsAsFactors = FALSE, encoding="UTF-8") | |
| coverage <- read.csv(paste("~/R/dumb_shit/import/","coverage.csv",sep=""), header = FALSE, sep = ",", quote = "\"",stringsAsFactors = FALSE, encoding="UTF-8") | |
| names(pop) <- c("City","State","Pop") | |
| names(coverage) <- c("City","State") | |
| find_match <- function(x) { | |
| result <- NA | |
| if(nrow(coverage[which(coverage$City==x["City"] & coverage$State==x["State"]),])>0) { | |
| result <- "Match" | |
| } | |
| return(result) | |
| } | |
| pop$Match <- apply(pop,1,find_match) | |
| write.csv(pop, file = "~/R/dumb_shit/export/pop.csv",na="") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment