在 tidyverse 中将列合并为一个

combining columns into one in tidyverse

是否可以使用 tidyverse 将 excel 的列合并为一个?这就是我现在拥有的

library(tidyverse)
library(dplyr)
data <- read_excel("chat.xls") %>%
  select(c('Question Answer', Transcript))

Tidyr 的 unite 会为您做到这一点。

library(tidyr)

iris %>% unite(New_Column, Sepal.Length,Species,Sepal.Width) 

输出:

> iris %>% unite(New_Column, Sepal.Length,Species,Sepal.Width)
            New_Column Petal.Length Petal.Width
1       5.1_setosa_3.5          1.4         0.2
2         4.9_setosa_3          1.4         0.2
3       4.7_setosa_3.2          1.3         0.2
4       4.6_setosa_3.1          1.5         0.2
5         5_setosa_3.6          1.4         0.2
6       5.4_setosa_3.9          1.7         0.4
7       4.6_setosa_3.4          1.4         0.3
8         5_setosa_3.4          1.5         0.2
9       4.4_setosa_2.9          1.4         0.2
10      4.9_setosa_3.1          1.5         0.1