Suppose the following data structure:
structure(list(`1.a` = c("a", NA, "a"), `1.b` = c("b", "b", NA
), `2` = c("ba", "ba", "ab"), `3.a` = c("a", "a", NA), `3.b` = c("b",
NA, "b")), row.names = c(NA, -3L), class = c("tbl_df", "tbl",
"data.frame"))
# A tibble: 3 x 5
`1.a` `1.b` `2` `3.a` `3.b`
<chr> <chr> <chr> <chr> <chr>
1 a b ba a b
2 NA b ba a NA
3 a NA ab NA b
Now, for the columns with .a etc., I want to create a column named X (the part/number before the dot) in front of the .a columns and paste the cell values together, keeping the "order". Result I want:
# A tibble: 3 x 7
`1` `1.a` `1.b` `2` `3` `3.a` `3.b`
<chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 ab a b ab ab a b
2 b NA b a a a NA
3 a a NA b b NA b