Typos in Vectors chapter (#490)
This commit is contained in:
parent
c81d1e0087
commit
e1e3e78b7c
18
vectors.Rmd
18
vectors.Rmd
|
@ -26,7 +26,7 @@ There are two types of vectors:
|
|||
1. __Lists__, which are sometimes called recursive vectors because lists can
|
||||
contain other lists.
|
||||
|
||||
The chief difference between atomic vectors is that atomic vectors are __homogeneous__, while lists can be __heterogeneous__. There's one other related object: `NULL`. `NULL` is often used to represent the absence of a vector (as opposed to `NA` which is used to represent the absence of a value in a vector). `NULL` typically behaves like a vector of length 0. Figure \@ref(fig:datatypes) summarises the interrelationships.
|
||||
The chief difference between atomic vectors and lists is that atomic vectors are __homogeneous__, while lists can be __heterogeneous__. There's one other related object: `NULL`. `NULL` is often used to represent the absence of a vector (as opposed to `NA` which is used to represent the absence of a value in a vector). `NULL` typically behaves like a vector of length 0. Figure \@ref(fig:datatypes) summarises the interrelationships.
|
||||
|
||||
```{r datatypes, echo = FALSE, out.width = "50%", fig.cap = "The hierarchy of R's vector types"}
|
||||
knitr::include_graphics("diagrams/data-structures-overview.png")
|
||||
|
@ -99,8 +99,7 @@ The distinction between integers and doubles is not usually important, but there
|
|||
some numerical tolerance.
|
||||
|
||||
1. Integers have one special value: `NA`, while doubles have four:
|
||||
`NA`, `NaN`, `Inf` and `-Inf`. All three special values can arise in
|
||||
during division:
|
||||
`NA`, `NaN`, `Inf` and `-Inf`. All three special values `NaN`, `Inf` and `-Inf` can arise in during division:
|
||||
|
||||
```{r}
|
||||
c(-1, 0, 1) / 0
|
||||
|
@ -415,7 +414,7 @@ x_named <- list(a = 1, b = 2, c = 3)
|
|||
str(x_named)
|
||||
```
|
||||
|
||||
Unlike atomic vectors, `lists()` can contain a mix of objects:
|
||||
Unlike atomic vectors, `list()` can contain a mix of objects:
|
||||
|
||||
```{r}
|
||||
y <- list("a", 1L, 1.5, TRUE)
|
||||
|
@ -458,7 +457,7 @@ There are three principles:
|
|||
|
||||
### Subsetting
|
||||
|
||||
There are three ways to subset a list, which I'll illustrate with `a`:
|
||||
There are three ways to subset a list, which I'll illustrate with a list named `a`:
|
||||
|
||||
```{r}
|
||||
a <- list(a = 1:3, b = "a string", c = pi, d = list(-1, -5))
|
||||
|
@ -478,8 +477,8 @@ a <- list(a = 1:3, b = "a string", c = pi, d = list(-1, -5))
|
|||
hierarchy from the list.
|
||||
|
||||
```{r}
|
||||
str(y[[1]])
|
||||
str(y[[4]])
|
||||
str(a[[1]])
|
||||
str(a[[4]])
|
||||
```
|
||||
|
||||
* `$` is a shorthand for extracting named elements of a list. It works
|
||||
|
@ -583,7 +582,8 @@ The most important S3 generic is `print()`: it controls how the object is printe
|
|||
Atomic vectors and lists are the building blocks for other important vector types like factors and dates. I call these __augmented vectors__, because they are vectors with additional __attributes__, including class. Because augmented vectors have a class, they behave differently to the atomic vector on which they are built. In this book, we make use of four important augmented vectors:
|
||||
|
||||
* Factors.
|
||||
* Date-times and times.
|
||||
* Date-times
|
||||
* Times.
|
||||
* Tibbles.
|
||||
|
||||
These are described below.
|
||||
|
@ -671,5 +671,5 @@ The main difference is the class. The class of tibble includes "data.frame" whic
|
|||
1. Try and make a tibble that has columns with different lengths. What
|
||||
happens?
|
||||
|
||||
1. Based of the definition above, is it ok to have a list as a
|
||||
1. Based on the definition above, is it ok to have a list as a
|
||||
column of a tibble?
|
||||
|
|
Loading…
Reference in New Issue