This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Combined two data frame of unequal length with similar header but difference in data in two columns

df1 <- data.frame(ID1 = c(1:3),ID2 = c(493:495),ID3 = c(2635:2637),X1 = c("15:03", "15:01", "03:01"),X2 = c("3","3","7"),X3 = c("2","2","5"),X4 = c("6","6","5"),X5 = c("1","24","3")) df2 <- data.frame(ID1 = c(1:5),ID2 = c(493:497),ID3 = c(2635:2639),X1 = c("15", "15", "03","07","02"),X2 = c("03:01","03:05","07","15:01","34"),X3 = c("2","2","5","34","36"),X4 = c("6","6","5","4","6"),X5 = c("1","24","3","39","40"))

I want combined_df looked like this:

data_combined <- data.frame(ID1 = c(1:5),ID2 = c(493:497),ID3 = c(2635:2639),X1 = c("15:03", "15:01", "03:01","07","02"),X2 = c("03:01","03:05","07","15:01","34"),X3 = c("2","2","5","34","36"),X4 = c("6","6","5","4","6"),X5 = c("1","24","3","39","40"))

I tried this but not get the desired result:

data_combined <- Reduce(function(x, y) merge(x, y, all=TRUE), list(df1,df2))

r

Hello Maneesh.Misra!

We believe that this post does not fit the main topic of this site.

Not a bioinformatics question.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

1 answer

Can anybody help me. Thanks in advance.

Log in to answer this question.