I have a vector of length 3 (my_vector
).
I want to bind this vector to an existing data.frame (my_df
) as a new column.
However, the data.frame has 4 rows. Thus, in the 4th row, the new column value (or my_df[4,3]
) should be NA
.
How can I achieve this?
When I do my_df$new_column <- my_vector
, I get the following error message:
replacement has 3 rows, data has 4
Here is my_df
(comprising 4 rows):
> dput(my_df)
structure(list(
person = c("Oleg", "Yurii", "Igor", "Mikhail"),
role = structure(c(1L, 2L, 2L, 3L), class = "factor", .Label = c("EDITOR-IN-CHIEF", "DEPUTY EDITORS-IN-CHIEF", "Coordinating Editor"))),
class = "data.frame", row.names = c(NA, -4L)
)
And my_vector
(of length 3):
> dput(my_vector)
c("Lomonosov University", "Russian Academy of Sciences", "Institute of Acoustics, Moscow, Russia")