1

How to add a column, which a predefined string of factors as a fourth column into anexisting data frame.

I have a tibble of 5X3 .,

I want to add a string of variables status <- c(0,0,1,1,0) as a fourth column. How can I do that?

# New column to add
status<- c(0,0,1,1,0)

# dataset
test<- structure(list(id = 1:5, weight = 63:67, height = 171:175), row.names = c(NA, 
-5L), class = c("tbl_df", "tbl", "data.frame"))
Cettt
  • 11,460
  • 7
  • 35
  • 58
Anandapadmanathan
  • 315
  • 1
  • 3
  • 8

1 Answers1

0

Just use mutate

library(dplyr)
status<- c(0,0,1,1,0)

test %>% 
  mutate(status = status)

Or you can use bind_cols:

test %>% bind_cols(status = status)

Or simply

test$status <- status
Cettt
  • 11,460
  • 7
  • 35
  • 58