a | b | c | d | e |
---|---|---|---|---|
1 | 2 | 3 | 900100 | 500 |
1 | 2 | 3 | 900200 | 0 |
4 | 5 | 6 | 500100 | 900 |
4 | 5 | 6 | 500200 | 0 |
I want to unite all the variables a:e
, mutate a new variable desired
:
- unite
a
andb
without any space - then unite with
c
with 1 space - then unite with
d
with 2 spaces - then unite with
e
with 3 spaces
Below is the desired output:
# A tibble: 4 x 1
desired
<chr>
1 12 3 900100 500
2 12 3 900200 0
3 45 6 500100 900
4 45 6 500200 0
library(tidyverse)
# toy data
df <- structure(list(a = c(1, 1, 4, 4), b = c(2, 2, 5, 5),
c = c(3, 3, 6, 6), d = c(900100, 900200, 500100, 500200),
e = c(500, 0, 900, 0)),
class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA,-4L))