【发布时间】:2020-12-07 13:51:39
【问题描述】:
在数据框中
df <- data.frame(id = c(12,35), col1 = c("ext", "another"))
如何添加一个在每一行中都包含相同文本的新列
示例输出
df <- data.frame(id = c(12,35), col1 = c("ext", "another"), mycol = c("mytext","mytext"))
【问题讨论】:
标签: r
在数据框中
df <- data.frame(id = c(12,35), col1 = c("ext", "another"))
如何添加一个在每一行中都包含相同文本的新列
示例输出
df <- data.frame(id = c(12,35), col1 = c("ext", "another"), mycol = c("mytext","mytext"))
【问题讨论】:
标签: r
以下应该这样做。
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
【讨论】:
我们也可以利用回收
data.frame(id = c(12,35), col1 = c("ext", "another"), mycol = "mytext")
【讨论】: