Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.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
cbind中的单引号,用于将数据追加到R中的数据帧_R_Dataframe - Fatal编程技术网

cbind中的单引号,用于将数据追加到R中的数据帧

cbind中的单引号,用于将数据追加到R中的数据帧,r,dataframe,R,Dataframe,我试图理解下面代码行中的语法。cbind函数中的单引号在这里做什么?如果可能,请举例说明。有关完整的代码示例,请访问此 这只是一种简便的方法,可以在结果data.frame中为附加列指定一个空(看起来)名称 比较: > data <- data.frame(a=1:3, b=4:6) > cbind(data, 1:3) a b 1:3 1 1 4 1 2 2 5 2 3 3 6 3 > cbind(data, ' '=1:3) a b 1 1 4

我试图理解下面代码行中的语法。cbind函数中的单引号在这里做什么?如果可能,请举例说明。有关完整的代码示例,请访问此


这只是一种简便的方法,可以在结果data.frame中为附加列指定一个空(看起来)名称

比较:

> data <- data.frame(a=1:3, b=4:6)
> cbind(data, 1:3)
  a b 1:3
1 1 4   1
2 2 5   2
3 3 6   3
> cbind(data, ' '=1:3)
  a b  
1 1 4 1
2 2 5 2
3 3 6 3

## And just to see for yourself that the column name is not really empty...
> names(cbind(data, ' '=1:3))
[1] "a" "b" " "
数据cbind(数据,1:3) a b 1:3 1 1 4 1 2 2 5 2 3 3 6 3 >cbind(数据,'=1:3) a b 1 1 4 1 2 2 5 2 3 3 6 3 ##让你自己看看列名并不是真的空的。。。 >名称(cbind(数据,'=1:3)) [1] a“b”
添加“空”命名列-
使用
检查数据列前后的对象值。我很惊讶列名没有变为”。我以为cbind.data.frame会调用“check.names”。
> data <- data.frame(a=1:3, b=4:6)
> cbind(data, 1:3)
  a b 1:3
1 1 4   1
2 2 5   2
3 3 6   3
> cbind(data, ' '=1:3)
  a b  
1 1 4 1
2 2 5 2
3 3 6 3

## And just to see for yourself that the column name is not really empty...
> names(cbind(data, ' '=1:3))
[1] "a" "b" " "