I have a data frame with the name of mydfwhere in the columns a, and bthere are items separated by a comma. What I want to do is combine the values ββin the columns aand bby removing (or ignoring) the values ββin parentheses ()and getting the column commonin result.
mydf
a b
1 at1 (1) , 23-x (0) at1,23-x,gt
2 hh (2) , pp (0) pp
3 cg (4) , gh (9) , th (7) th,cg
result
a b common
1 at1 (1) , 23-x (0) at1,23-x,gt at1,23-x
2 hh (2) , pp (0) pp pp
3 cg (4) , gh (9) , th (7) rh,cg cg
Data:
mydf <- read.table(
text = "a|b
at1 (1) , 23-x (0)|at1,23-x,gt
hh (2) , pp (0)|pp
cg (4) , gh (9) , th (7)|th,cg",
sep = "|", header = TRUE,
colClasses = rep("character", 2)
)
source
share