![](/img/trans.png)
[英]Does R have a function for the logarithm that deals with negative numeric values?
[英]Does R have “negative zero”?
我的控制台告訴我-0
返回0
並且c(1:5)[0]
和c(1:5)[-0]
返回integer(0)
。 R 這是否意味着 R 沒有“負零”的概念?
盡管 R 很好地隱藏了它,但實際上 R 確實有一個負零:
# R says these are the same
0 == -0
## [1] TRUE
identical(0, -0)
## [1] TRUE
# but they are not
is.neg0 <- function(x) x == 0 && sign(1/x) == -1
is.neg0(0)
## [1] FALSE
is.neg0(-0)
## [1] TRUE
R 中的索引從 1 開始,允許索引 0,但表示一個空向量( R 語言定義)。 負號表示“給我列表中的所有元素,但我在索引中指定的元素除外” ,即c(1:5)[-2]
返回[1] 1 3 4 5
。 在您的情況下,索引 0 和 -0 之間沒有區別,它們代表相同的行為。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.