I have two data.table
objects in R:
library(data.table)
spp <- c('A','B','C','D','E')
state <- c('Z','Q',NA,'Z','Q')
d1 <- data.table(spp,state)
spp <- c('C','B','K')
state <-c('Z','Q','Q')
d2 <- data.table(spp,state)
The observation C
in column spp
of d1
has an NA value in column state
. However, in d2
the observation C
in column spp
has the value Z
in column state
. How can I update the state
column of d1
, adding the state
observations from d2
when there is a spp
observation that is common to both d1
and d2
?