Could someone explain me the output of "str("Hello") == str("World!")" in R. I was expecting "TRUE"

huangapple go评论67阅读模式
英文:

Could someone explain me the output of "str("Hello") == str("World!")" in R. I was expecting "TRUE"

问题

以下是您提供的文本的中文翻译部分:

我只是在学习R语言,我尝试了这个:
str("Hello") == str("World!")

我期望得到一个逻辑输出,比如TRUE或FALSE,但实际上返回了这个:
chr "Hello"; chr "World!"; logical(0)

我不明白为什么,因为str()函数应该打印括号内的类和内容...
能有人帮我理解一下吗,请?

非常感谢。

尝试过:str("Hello") == str("World!")
期望: "TRUE" 或 "FALSE"
实际情况:
chr "Hello"; chr "World!"; logical(0)

英文:

I'm just learning R, and I tried this:
str("Hello") == str("World!")

I was expecting an logical output, like TRUE or FALSE, but instead, it returned this:
chr "Hello"
chr "World!"
logical(0)

I didn't understand why, bacause the str() function should print the class and whatever is inside parenthesis...
Could someone help me in understanding this, please?

Many thanks.

Tried: str("Hello") == str("World!")
Expected: "TRUE" or "FALSE"
Reality:
chr "Hello"
chr "World!"
logical(0)

答案1

得分: 4

以下是翻译好的部分:

看到以下内容。

tmp <- str("Hello")
print(tmp)

返回的结果是:

chr "Hello"
NULL

所以你可以看到 NULL 被赋给了 tmp。对于 str("whatever") 也是一样的。

所以你在进行以下比较:

NULL == NULL

显然是 logical(0)

英文:

See the following.

tmp &lt;- str(&quot;Hello&quot;) 

print(tmp) 

is returning:

chr &quot;Hello&quot;
NULL

So you see that NULL is assigned to tmp. The same is for str(&quot;whatever&quot;).

So you are calling :

NULL == NULL

That's obviously logical(0)

huangapple
  • 本文由 发表于 2023年2月19日 02:26:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75495474.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定