I am trying to amalgamate two rows together so that the output is best of both worlds. I have read through some of the solutions using ddply
or aggregate
, however they work only with numeric data.
Below is an example of what I am trying to do.
Input:
x <- c("Yemen", 1, NA, NA, 4, 5, "Six")
y <- c("Yemen", NA, "B", 3, NA, 6, "Six")
DF <- as.data.frame(rbind(x,y))
colnames(DF)[1] <- c("CNTRY")
Output
"Yemen", 1, "B", 3, 4, 5, "Six"
where the key is CNTRY
Ideally, I should be able to choose whether to retain value of x
or y
if they are different.
Edit 1:
The solution should work on a data frame DF
in this example and not x
& y
. My data frame has multiple accounts which are duplicated and I am trying to merge all of the rows that have more than one instance but share the account (key).