- R Programming By Example
- Omar Trejo Navarro
- 327字
- 2021-07-02 21:30:36
Special values
There are a few special values in R. The NA values are used to represent missing values, which stands for not available. If a computation results in a number that is too big, R will return Inf for a positive number and -Inf for a negative number, meaning positive and negative infinity, respectively. These are also returned when a number is pided by 0. Sometimes a computation will produce a result that makes little sense. In these cases, we will get a NaN, which stands for not a number. And, finally, there is a null object, represented by NULL. The symbol NULL always points to the same object (which is a data type on its own) and is often used as a default argument in functions to mean that no value was passed through. You should know that NA, Inf, -Inf, NaN, and NULL are not substitutes for each other.
There are specific NA values for numerics, characters, and logicals, but we will stick to the simple NA, which is internally treated as a logical.
In the following example, you can see how these special values behave when used among themselves in R. Note that 1 / 0 results in Inf, 0 / 0, Inf - Inf, and Inf / Inf results in undefined represented by NaN, but Inf + Inf, 0 / Inf, and Inf / 0, result in Inf, 0, and Inf, respectively. It's no coincidence that these results resemble mathematical definitions. Also note that any operation including NaN or NA will also result in NaN and NA, respectively:
1 / 0
#> [1] Inf -1 / 0
#> [1] -Inf 0 / 0
#> [1] NaN Inf + Inf
#> [1] Inf Inf - Inf
#> [1] NaN Inf / Inf
#> [1] NaN Inf / 0
#> [1] Inf 0 / Inf
#> [1] 0 Inf / NaN
#> [1] NaN Inf + NA
#> [1] NA
- ABB工業機器人編程全集
- Canvas LMS Course Design
- 基于LabWindows/CVI的虛擬儀器設計與應用
- R Machine Learning By Example
- Python Algorithmic Trading Cookbook
- Creo Parametric 1.0中文版從入門到精通
- WordPress Theme Development Beginner's Guide(Third Edition)
- 新手學電腦快速入門
- AI 3.0
- 基于單片機的嵌入式工程開發詳解
- Nginx高性能Web服務器詳解
- 電氣控制與PLC技術應用
- 從零開始學PHP
- Spark大數據商業實戰三部曲:內核解密|商業案例|性能調優
- 一步步寫嵌入式操作系統