October 2019
Intermediate to advanced
316 pages
9h 45m
English
In Step 1, we create a function that, given a vector, returns only a single value (a vector of length one). We then use it in mutate() to add a column called result and get the following:
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species result ## 1 5.1 3.5 1.4 0.2 setosa 563.7 ## 2 4.9 3.0 1.4 0.2 setosa 563.7 ## 3 4.7 3.2 1.3 0.2 setosa 563.7 ## 4 4.6 3.1 1.5 0.2 setosa 563.7
Note how the single value the function returns in the result column is repeated over and over. With length == 1 vectors, R will recycle the result and place it in every position.
In Step 2, we go to the opposite end and create a function that, given a vector, returns a vector of identical length (specifically, it returns a vector of the ...
Read now
Unlock full access