Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在每行中创建一个具有特定字符串的新列_R - Fatal编程技术网

R 在每行中创建一个具有特定字符串的新列

R 在每行中创建一个具有特定字符串的新列,r,R,在数据帧中 df <- data.frame(id = c(12,35), col1 = c("ext", "another")) df下面的步骤应该可以完成 df <- data.frame(id = c(12,35), col1 = c("ext", "another")) df$mycol <- "mytext" # id col1 mycol # 1 1

在数据帧中

df <-  data.frame(id = c(12,35), col1 = c("ext", "another"))

df下面的步骤应该可以完成

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

df我们也可以利用回收

data.frame(id = c(12,35), col1 = c("ext", "another"), mycol = "mytext")
data.frame(id = c(12,35), col1 = c("ext", "another"), mycol = "mytext")