Merge in RStudio (joins)

Hello Friends,

Can you help me with this merge?

FIRST <- data.frame(ID = c(1, 2, 3, 4, 5, 6),
                    A = c(1212,1313, "", "", "", ""))
FIRST

SECOND <- FIRST <- data.frame(ID2= c(1, 2, 3, 4, 5, 6),
                              B = c("", "", 1414,1515,1616,1717))
SECOND

The ideal OUTPUT:

ID2 B
1 1 1212
2 2 1313
3 3 1414
4 4 1515
5 5 1616
6 6 1717

THANK YOU!!

Try this:

library(tidyverse)

FIRST <- data.frame(ID = c(1, 2, 3, 4, 5, 6),
                    A = c(1212,1313, "", "", "", ""))

SECOND <- data.frame(ID2= c(1, 2, 3, 4, 5, 6),
                     B = c("", "", 1414,1515,1616,1717))

left_join(FIRST, SECOND, by = c("ID" = "ID2")) %>% 
  unite("B", A:B, sep = "")
  ID    B
1  1 1212
2  2 1313
3  3 1414
4  4 1515
5  5 1616
6  6 1717

THANKS A LOT WILL!!!
LOVELY SOLUTION!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.