我有向量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
答案 0 :(得分:1)
library(dplyr)
tib <- tibble(first = rep(1, 3),
second = rep(1, 3))
vec <- c(1,2,3)
tib %>%
mutate(third = vec)