R按值传递或按引用传递

时间:2018-12-06 01:08:54

标签: r pass-by-reference pass-by-value

例如,如果我在R中创建函数,则:

f<-function(x){
x
.....

}

执行函数R使用按值传递或按引用传递时

1 个答案:

答案 0 :(得分:-1)

In R it is call by value. To prove this i tried with a small function as below;

f1 <- function(a,b){

  print(a)

  #print b value before call
  print(b)

  fi(b)
  #print b value after call
  print(b)

}

fi <- function(i){
   i = i + 20
}

f1(10,20)

output :
----------
[1] 10
[1] 20
[1] 20