So, I have two dataset representing old and current address.
> main
idspace id x y move
198 1238 33 4 stay
641 1236 36 12 move
1515 1237 30 28 move
> move
idspace id x y move
4 1236 4 1 move
What I need is to merge the new data (move
) with the old (main
) and update main
once merged.
I was wondering if it was possible to it in one operation ?
The update is based on id
, wich is the personal identifier.
idspace
, x
, y
are the location id.
So, the output I need is
> main
idspace id x y move
198 1238 33 4 stay
4 1236 4 1 move # this one is updated
1515 1237 30 28 move
I have no clue how I can do this.
Something like
merge(main, move, by = c('id'), all = T, suffixes = c('old', 'new'))
However, this is wrong because I need to do so many manipulations by hand.
Any solution ?
data
> dput(main)
structure(list(idspace = structure(c(2L, 3L, 1L), .Label = c("1515",
"198", "641"), class = "factor"), id = structure(c(3L, 1L, 2L
), .Label = c("1236", "1237", "1238"), class = "factor"), x = structure(c(2L,
3L, 1L), .Label = c("30", "33", "36"), class = "factor"), y = structure(c(3L,
1L, 2L), .Label = c("12", "28", "4"), class = "factor"), move = structure(c(2L,
1L, 1L), .Label = c("move", "stay"), class = "factor")), .Names = c("idspace",
"id", "x", "y", "move"), row.names = c(NA, -3L), class = "data.frame")
> dput(move)
structure(list(idspace = structure(1L, .Label = "4", class = "factor"),
id = structure(1L, .Label = "1236", class = "factor"), x = structure(1L, .Label = "4", class = "factor"),
y = structure(1L, .Label = "1", class = "factor"), move = structure(1L, .Label = "move", class = "factor")), .Names = c("idspace",
"id", "x", "y", "move"), row.names = c(NA, -1L), class = "data.frame")`