Reputation: 187
In a dataframe
df <- data.frame(id = c(12,35), col1 = c("ext", "another"))
How is it possible to add a new column which will contain in every row the same text
Example output
df <- data.frame(id = c(12,35), col1 = c("ext", "another"), mycol = c("mytext","mytext"))
Upvotes: 0
Views: 913
Reputation: 887118
We can also make use the recycling
data.frame(id = c(12,35), col1 = c("ext", "another"), mycol = "mytext")
Upvotes: 0
Reputation: 1926
The following should do it.
df <- data.frame(id = c(12,35), col1 = c("ext", "another"))
df$mycol <- "mytext"
# id col1 mycol
# 1 12 ext mytext
# 2 35 another mytext
Upvotes: 1