i have two data frames.
one is structured like this:
code. name.
1111 A B
1122 C D
2122 C D
2133 G H
the other is:
code_2. name.
11 F
21 G
i want to obtain a third df that, in relation to code match, concatenate my data present in the first data frame, using a "OR" separator. The code value that I want to mantain is the the one of the second df. It is important that the match among code values would be made on the first and second number of the code belonging to the first dataframe.
code. name.
11 A B OR C D
21 C D OR G H
thank you for your suggestions!
You can use aggregate
, i.e.
aggregate(name. ~ substr(code., 1, 2), df, paste, collapse = ' OR ')
# substr(code., 1, 2) name.
#1 11 A B OR C D
#2 21 C D OR G H
You can take care of the column names as usual.