Hello i would like to know how can i merge 2 data frames in R,there is a merge function ,but i would like to do this :
data frame1
X Y Z
1 1 1 1
2 1 1 1
3 1 1 1
4 1 1 1
5 1 1 1
data frame 2
A B C
1 2 2 2
2 2 2 2
3 2 2 2
mergedataframe
X Y Z A B C
1 1 1 1
2 1 1 1
3 1 1 1 2 2 2
4 1 1 1 2 2 2
5 1 1 1 2 2 2
the think is i must synchronize 3 csv files (dataframe) and i have no idea how to it with R.
if somebody have any idea about it ,thank u
i redit my post i would like my merged data frame like that :
data frame1
X Y Z
1 1 1 1
2 1 1 1
3 1 1 1
4 1 1 1
5 1 1 1
6 1 1 1
data frame 2
A B C
1 2 2 2
2 2 2 2
mergedataframe
X Y Z A B C
1 1 1 1
2 1 1 1
3 1 1 1 2 2 2
4 1 1 1 2 2 2
5 1 1 1
6 1 1 1
df1 <- data.frame(X=rep(1,5),Y=1, Z=1)
df2 <- data.frame(A=rep(2,3),B=2, C=2)
#rownames(df2) <- 3:5
rownames(df2) <- tail(rownames(df1), nrow(df2))
mergedataframe <- merge(df1,df2, by=0, all=TRUE)
mergedataframe <- mergedataframe[,-1]
mergedataframe
X Y Z A B C
1 1 1 1 NA NA NA
2 1 1 1 NA NA NA
3 1 1 1 2 2 2
4 1 1 1 2 2 2
5 1 1 1 2 2 2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.