| Start |
|---|
| Creating named vectors Named vector can be created in several ways. With which results in: with which results in: With the which results in a named integer vector: As can be seen, this gives the same result as the You may also use the With such a vector it is also possibly to select elements by name: This feature makes it possible to use such a named vector as a look-up vector/table to match the values to values of another vector or column in dataframe. Considering the following dataframe: Suppose you want to create a new variable in the which results in: |
| Vectors from build in constants: Sequences of letters & month names
From the letters and month constants, vectors can be created. 1) Sequences of letters: 2) Sequences of month abbreviations or month names: |
| Sequence of numbers Use the This works both ways and even with floating point numbers or negatives |
| seq()
The function creates a sequence from the You can supply only the end ( As well as the start And finally the step (
If the sequence needs to have the same length as another vector we can use the There are two useful simplified functions in the Note that
There is also an old function |
| Creating vectors |
| Expanding a vector with the rep() function The The each argument is especially useful for expanding a vector of statistics of observational/experimental units into a vector of data.frame with repeated observations of these units. A nice feature of This should expose the possibility of allowing an external function to feed the second argument of As with |
Read Article
https://develop.horje.com/learn/1434/reference