Skip to content
Prev 255871 / 398503 Next

Help to check data before putting it in a database

Hi Ulisses,

Look at the functions ?match and ?rbind

If you do not want to do it by hand, you can make a little function as below.

HTH,

Josh

d1 <- data.frame(goals = 4:1, players = LETTERS[1:4])
d2 <- data.frame(goals = c(1, 3, 2, 5), players = LETTERS[3:6])

f <- function(old, new, check) {
  index <- new[, check] %in% old[, check]
  dat <- rbind(old, new[index, ])
  tocheck <- new[!index, ]
  list(merged = dat, tocheck = tocheck)
}

dmerged <- f(d1, d2, "players")
## check "tocheck" and once it is correct
dfinal <- do.call("rbind", dmerged)

On Tue, Apr 5, 2011 at 8:06 AM, Ulisses.Camargo
<moliterno.camargo at gmail.com> wrote: