-2

I have vector vec<-1,2,3. I have tibble that looks like:

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

Now I need to add vector vec to my existing tibble as variable (column) so that tibble should look like:

first | second | third
1     |1          |1
1     |1          |2
1     |1          |3
vasili111
  • 6,032
  • 10
  • 50
  • 80
  • 3
    I'm guessing this is related to your other question, and I think they're both based on the misunderstanding of what a tibble is: it's still a data frame. Something you could do with a data frame (`df$x <- new_vector` here, `cbind(df1, df2)` in the other), you can generally do with a tibble. – camille May 15 '19 at 22:55

1 Answers1

1
library(dplyr)

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

tib %>%
  mutate(third = vec)
Jon Spring
  • 55,165
  • 4
  • 35
  • 53