Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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,我在哈德利·威克姆的书的网站上读到了他的《高级R》。我发现了一个关于R中替换函数的问题。下面的结果是根据他的书给出的 library(pryr) x <- 1:10 address(x) #> [1] "0x103945110" x[2] <- 7L address(x) #> [1] "0x103945110" 库(pryr) x[1]“0x103945110” x[2][1]“0x103945110” 他认为如果我们只替换x的第二个元素,x的地址就不会改变。然而

我在哈德利·威克姆的书的网站上读到了他的《高级R》。我发现了一个关于R中替换函数的问题。下面的结果是根据他的书给出的

library(pryr)
x <- 1:10
address(x)
#> [1] "0x103945110"

x[2] <- 7L
address(x)
#> [1] "0x103945110"
库(pryr)
x[1]“0x103945110”
x[2][1]“0x103945110”
他认为如果我们只替换x的第二个元素,x的地址就不会改变。然而,当我这样做的时候,x的物理地址实际上改变了。有人告诉我为什么吗?

有一次。如果你试着用同样的例子

library(pryr)
x <- c(1,2,3,4,5,6,7,8,9,10)
address(x)
x[2] <- 7L
address(x)
库(pryr)

x您是否运行了准确的代码?请注意,如果您使用了
7
而不是
7L
,这是对代码的更改。我可以复制该问题。我得到一个地址更改,在macOS Sierra上运行64位R3.4.0,
pryr
0.1.3版。这里也是,x86_64-w64-mingw32,R3.5.0,pryr 0.1.4,在这里找到源代码:你是在Rstudio还是在基本的R GUI中运行?如果是这样,Rstudio将引用变量。可能重复: