0

my original frame date

DF1<- data.frame(
plot = I(c("A", "B", "C", "D", "E")),
value = c(1:5)
)

DF2 <- data.frame(
plot= I(c("A", "A", "B",
         "B", "B", "C", "D","D","E","E","E")),
sp = c("sp1",
          "sp2",
          "sp1",
          "sp2", "sp3","sp2","sp3","sp4","sp1","sp2","sp4"),
value = NA)

the data frame that you would like to get after merge the two original date frame

DF.result <- data.frame(
plot= I(c("A", "A", "B",
         "B", "B", "C", "D","D","E","E","E")),
sp = c("sp1",
          "sp2",
          "sp1",
          "sp2", "sp3","sp2","sp3","sp4","sp1","sp2","sp4"),
value = c(rep(1,2),rep(2,3),3,rep(4,2),rep(5,3))
  • 1
    `merge(DF1, DF2[1:2], all = T)`. This is called a "full join" or "full outer join". (And we don't include the all-NA column in DF2 because you just want the values from DF1.) – Gregor Thomas Jan 09 '18 at 14:59
  • You may want to review [the different types of joins](https://stackoverflow.com/a/20298671/903061). – Gregor Thomas Jan 09 '18 at 15:03

0 Answers0