Merging dataframes by columns where some columns exist in both dataset but
some do not
Suppose you have two datasets, x and y:
x=matrix(c(1,2,55,3,2,1,0,NA,NA,3,NA,333,NA,9,NA),5,3)
colnames(x)=c(1133131,12442141,20100063)
rownames(x)=c(1,2,3,4,5)
y=matrix(c(8,1,3,41,131,NA,4141,NA,124,NA,213,NA,128,NA,2,NA,1241,2),3,6)
colnames(y)=c(1133131,2422342,555555,33323242,20100063,23325600009)
rownames(y)=c(6,7,8)
I want to merge them so that all columns are present in the final dataset,
and the data is filled in where it exists, and NA where it is not. So if
one is not present in the other dataset, I want all its values to be NA
for that part.
So basically I want the final output to be:
merged: upc
days 1133131,12442141,2422342,555555,33323242,20100063,23325600009
1 1 1 NA
2 2 0 NA
3 55 NA NA
4 3 NA NA ...etc
5 2 3 NA
6 8 NA 41
7 1 NA 131
8 3 NA NA
Thank you for your input.
No comments:
Post a Comment