Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nothingness concept #272

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions concepts/nothingness/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"authors": ["colinleach"],
"contributors": [],
"blurb": "R uses NULL for complete absence of a value, NA for gaps in our knowledge of the data."
}
65 changes: 65 additions & 0 deletions concepts/nothingness/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# About

Many languages have a way such as `null` or `none` to indicate a non-existent value.
Because R is designed to handle large volumes of (often messy) data, it has multiple forms of nothingness.

The overall aim is to flag missing or suspect values as they are encountered, then continue without raising an exception.

## NULL

If a value really doesn't exist, it is repesented by `NULL`. This is probably closest to what C or Python might do.

```R
> v <- c() # zero-length vector
> v
NULL
> is.null(v)
[1] TRUE
```

In many contexts, `NULL` values are simply ignored:

```R
> c(2, 3, NULL, 5)
[1] 2 3 5
```

## NA

For situations where a value exists but we don't know what it is, `NA` is used. For example, when counting vehicles traveling on a road, human observers might go off sick or automatic sensors break down, but the traffic continues to flow.

```R
> v <- c(1, 2, NA, 4, 5)
> v
[1] 1 2 NA 4 5
> is.na(v) # test for data gaps
[1] FALSE FALSE TRUE FALSE FALSE
```

Thus `NA` is a placeholder, warning humans that they need to make a decision about how to handle this.

Statistical functions usually return `NA` by default if `NA` values are present.
If you want these values to be ignored, use the `na.rm` (NA remove) parameter to make this explicit:

```R
> v <- c(1, 2, NA, 4, 5)
> mean(v)
[1] NA
> mean(v, na.rm = TRUE)
[1] 3
```

## NaN

Short for "Not a Number", this flags a computation problem in situations where a number was expected.

```R
> n <- c(0, 2, 4)
> d <- c(0, 1, 2)
> n / d
[1] NaN 2 2 # 0/0 is mathematically undefined

```

This is not the only possibility for "invalid" calculations.
Dividing by zero will return `Inf` or `-Inf` for a non-zero numerator, without raising an error.
39 changes: 39 additions & 0 deletions concepts/nothingness/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Introduction

Many languages have a way such as `null` or `none` to indicate a non-existent value.
Because R is designed to handle large volumes of (often messy) data, it has multiple forms of nothingness.

The overall aim is to flag missing or suspect values as they are encountered, then continue without raising an exception.

## NULL

If a value really doesn't exist, it is repesented by `NULL`. This is probably closest to what C or Python might do.

```R
> v <- c() # zero-length vector
> v
NULL
> is.null(v)
[1] TRUE
```

In many contexts, `NULL` values are simply ignored:

```R
> c(2, 3, NULL, 5)
[1] 2 3 5
```

## NA

For situations where a value exists but we don't know what it is, `NA` is used. For example, when counting vehicles traveling on a road, human observers might go off sick or automatic sensors break down, but the traffic continues to flow.

```R
> v <- c(1, 2, NA, 4, 5)
> v
[1] 1 2 NA 4 5
> is.na(v) # test for data gaps
[1] FALSE FALSE TRUE FALSE FALSE
```

Thus `NA` is a placeholder, warning humans that they need to make a decision about how to handle this.
10 changes: 10 additions & 0 deletions concepts/nothingness/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"url": "http://www.cookbook-r.com/Basics/Working_with_NULL_NA_and_NaN/",
"description": "Cookbook for R"
},
{
"url": "https://r02pro.github.io/null.html",
"description": "R Programming: Zero to Pro"
}
]
5 changes: 5 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@
"uuid": "2751b6f2-7d71-4397-b063-9bf927a57756",
"slug": "booleans",
"name": "Booleans"
},
{
"uuid": "f6374c07-9244-44b2-b372-3e271b0d01be",
"slug": "nothingness",
"name": "Nothingness"
}
],
"key_features": [
Expand Down