-4

I don't understand the difference between "=" and "==" in R. I have a few questions:

  • Why does = assign when in a script but not when in a function?
  • Why should I use <- when = exists? Is there a difference?
4

2 回答 2

9

我从来没有写过,r但我几乎可以肯定地告诉你,=赋值运算符是赋值运算符,而==相等运算符是。一个快速的谷歌搜索将很容易回答你有这样的问题。

似乎箭头运算符<-在 R 中更常用于赋值,而不是=.

任务:

x = 3
x <- 3

测试相等性:

if (x == 3)
于 2013-01-21T07:22:46.077 回答
1

=用于分配和设置功能参数。

==用于比较变量:测试相等性。

于 2013-01-21T07:26:23.177 回答