Entering edit mode
6.2 years ago
ersan
▴
10
How can i merge two or more column which are seperated with";" in one column using with R? Thanks
How can i merge two or more column which are seperated with";" in one column using with R? Thanks
library(tidyverse)
data <- tibble(x = c("a;b;c;","a2;b2;c2;","a3;b3;c3;") , y = c("x;y;z;","x2;y2;z2;","x3;y3;z3;"))
out <- data %>% mutate(pp = map(seq_along(x) , function(.) {
x_split <- unlist(strsplit(x[.] , ";"))
y_split <- unlist(strsplit(y[.] , ";"))
paste0(x_split , y_split , collapse = "</b></br><b>")
} )) %>% tidyr::unnest()
> out
# A tibble: 3 x 3
x y pp
<chr> <chr> <chr>
1 a;b;c; x;y;z; ax</b></br><b>by</b></br><b>cz
2 a2;b2;c2; x2;y2;z2; a2x2</b></br><b>b2y2</b></br><b>c2z2
3 a3;b3;c3; x3;y3;z3; a3x3</b></br><b>b3y3</b></br><b>c3z3
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Can you please post some example or expected output?
Output