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: 
You should separate the data frame into two data frames: one containing the even rows and another the odd rows. **Caution:** If there is an odd number of rows, the last row will contain `NA` in the new added columns.

Odd rows: `df[seq(1, nrow(df), 2), ]`

Even rows: `df[seq(2, nrow(df), 2), ]`

The next step is to `cbind` them:

```
df_new = cbind(df[seq(1, nrow(df), 2), ], df[seq(2, nrow(df), 2), ])

```

The last step should be to rename the columns:

```
colnames(df_new) = c("COL1", "COL2", "COL3", "COL4")

```
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)

```