简体   繁体   English

*在R中是什么意思?

[英]What does * means in R?

For instance: 例如:

> TRUE * 0.5
   0.5
> FALSE * 0.5
   0

I don't know if the secret here is the * character itself or the way R encodes logical statements, but I can't understand why the results. 我不知道这里的秘密是*字符本身还是R编码逻辑语句的方式,但是我不明白为什么要这样做。

R has a fairly loose type system and rather freely does coercion, hopefully when it is sensible. R有一个比较宽松的类型系统,并且相当自由地进行强制转换,希望它是明智的。 When coerced to numeric by * , logical values become 0 (FALSE) and 1 (TRUE), your expression gets evaluated with the usual mathematical convention of all values times 0 equal 0, and all values times 1 equal the value. 当用*强制将其强制为数字时,逻辑值变为0(FALSE)和1(TRUE),将使用通常的数学惯例对表达式进行求值,即所有值乘以0等于0,并且所有值乘以1等于该值。 The one exception to that rule in the numeric domain is Inf * 0 returns NaN . 在数字域中该规则的一个例外是Inf * 0返回NaN Character values have no "destination"-type when composed with "*", so "1"*TRUE throws an error. 字符值由“ *”组成时没有“目标”类型,因此"1"*TRUE会引发错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM