Closed:Combined two data frame of unequal length with similar header but difference in data in two columns
1
0
Entering edit mode
7.9 years ago

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 • 918 views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 1864 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6