Skip to content

Instantly share code, notes, and snippets.

@MattSandy
Created May 14, 2016 00:11
Show Gist options
  • Select an option

  • Save MattSandy/20e43153a7e656bab549de6247639081 to your computer and use it in GitHub Desktop.

Select an option

Save MattSandy/20e43153a7e656bab549de6247639081 to your computer and use it in GitHub Desktop.
Create Column that Mark Rows as Matched between Two Datasets
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