I The Story of Vector V: an R markdown example
This is an example of R markdown text that can be cut and pasted in a new R markdown document (section 13.2.2) and then knitted into an HTML or other type of document. This illustrates the use of R
code in chunks (shown or hidden) and as inline commands.
Note: Depending on the format (HTML/PDF) of this document some elements might have a background color. However, ALL these apparent parts constitute the .Rmd
file.
---
title: "The story of vector **V**"
output: html_document
---
# `V` learns numbers
Once upon a time there was a vector named `V` that was feeling
empty and was trying to learn numbers from `0` through `9`. One
day `V` met the *magical* combine function `c()` that was able
to add the numbers ***inside*** `V`, like this:
```{r}
V <- c(1,2,3,4,5,6,7,8,9)
```
`V` was very happy, and `V` was now spending its time enumerating
the numbers: `r V`. Sometimes it would pick one at random:
`r sample(V, 1)` and it was pleased that it was not always the
same number coming up.
## `V` wonders about itself
Wanting to know itself better `V` asked:
* what is my class? And the answer was: ``r class(V)``
* how long am I? And the answer came as ``r length(V)``
# `V` wants more
But then `V` wanted more: it wanted to add these numbersbut not
in the open like this, it wanted to do that "in its head" so it
could be done like this: **`r sum(V)`** (*and the value will be
printed here directly as calculate by `R`.*)
## `V` meets the Math Wizard
But how to describe that to *Math Wizards*?
`V` asked the beloved *fairy* friend *Equation*
who gave `V` the *magic* codes:
$$\sum_{n=1}^{9} n = sum(V)$$
which is still **`r sum(V)`**.
## `V` in the land of vectorization
But `V` wanted more again... `V` wanted to be 10 times more.
So `V` went on a journey across the land to know what to do.
It was a long and arduous journey, but `V` ended in the
*Land of Vectorization* and there, `V` was augmented 100 times
to be like this: `r 100*V`. But it was cumbersome to feel
these big numbers and *division* helped one more time to
make it just 10 times smaller to be `r 10*(V)`
# `V` and the mental picture
This time `V` wanted to have a mental "picture" of the numbers
and `V` could think of 2 ways, the `R` code had to be kept
*secret* so that the code would not be stolen:
```{r echo=FALSE, fig.height=3}
par(mfrow = c(1,2))
plot(V)
boxplot(V)
par(mfrow = c(1,1))
```