Question: I have a messy dataset that has 2 rows of info that belongs on 1. I would like to take the second row and slap it on the end of the first row and create new columns in the process.

```
For example, I would like:

       COL1      COL2
1     name1    score1
2    state1   rating1
3     name2    score2
4    state2   rating2

To become:

      COL1      COL2     COL3      COL4
1    name1    score1   state1   rating1
2    name2    score2   state2   rating2

```

Is there anything simplistic in the Hadleyverse for this?

Answer: 
I would do this using `unite()` and `separate()` from tidyr, and `lead()` from dplyr.

```r
library(dplyr)
library(tidyr)

df <- tribble(
~COL1,      ~COL2,
"name1",    "score1",
"state1",   "rating1",
"name2",    "score2",
"state2",   "rating2"
)

df %>% 
  unite(old_cols, COL1, COL2) %>%
  mutate(new_cols = lead(old_cols)) %>%
  filter(row_number() %% 2 == 1) %>%
  separate(old_cols, into = c("COL1", "COL2")) %>%
  separate(new_cols, into = c("COL3", "COL4"))

#> # A tibble: 2 x 4
#>    COL1   COL2   COL3    COL4
#> * <chr>  <chr>  <chr>   <chr>
#> 1 name1 score1 state1 rating1
#> 2 name2 score2 state2 rating2

```
Here is a `dplyr` solution.

```
library(dplyr)

dt2 <- dt %>%
  mutate(Group = rep(1:2, times = nrow(.)/2)) %>%
  split(.$Group) %>%
  bind_cols() %>%
  select(-starts_with("Group")) %>%
  setNames(paste0("COL", 1:ncol(.)))
dt2
   COL1   COL2   COL3    COL4
1 name1 score1 state1 rating1
2 name2 score2 state2 rating2

```

Or we can also use the `purrr` package with `dplyr` package.

```
library(dplyr)
library(purrr)

dt2 <- dt %>%
  mutate(Group = rep(1:2, times = nrow(.)/2)) %>%
  split(.$Group) %>%
  map_dfc(. %>% select(-Group)) %>%
  setNames(paste0("COL", 1:ncol(.)))
dt2
   COL1   COL2   COL3    COL4
1 name1 score1 state1 rating1
2 name2 score2 state2 rating2

```

**DATA**

```
dt <- read.table(text = "       COL1      COL2
1     name1    score1
                 2    state1   rating1
                 3     name2    score2
                 4    state2   rating2",
                 header = TRUE, stringsAsFactors = FALSE)

```