如何将矢量添加到tibble作为变量(列)

时间:2019-05-15 21:35:55

标签: r vector dplyr tidyverse tibble

我有向量vec<-1,2,3。我的表情像:

first | second 
1     |1
1     |1
1     |1

现在,我需要将矢量vec添加到现有的小节中作为变量(列),以便小节应如下所示:

first | second | third
1     |1          |1
1     |1          |2
1     |1          |3

1 个答案:

答案 0 :(得分:1)

library(dplyr)

tib <- tibble(first  = rep(1, 3),
       second = rep(1, 3)) 
vec <- c(1,2,3)

tib %>%
  mutate(third = vec)