Hi.
i'm trying to merge two columns but getting some issue.
my data looks like the following:
ad<-c("",3,4,5,6,7,"")
r<-c("2","3","","","6","","8")
dataw<-data.frame(ad,r)
> dataw
> ad r
> 1 2
> 2 3 3
> 3 4
> 4 5
> 5 6 6
> 6 7
> 7 8
this what I have done
mutate(dataw,New_Col=paste(ad,r))->dataw
the result looks like the following:
ad r New_Col
2 2
3 3 3 3
4 4
5 5
6 6 6 6
7 7
8 8
I want the value to be added in the new column only if it exist in either ad or r. And if the value in ad an r are the same then only one should be added to the new column.
I need a solution that can be generalized to a large number of variables
How can I do this?
Thanks in advance