| Start |
|---|
| Recycling use in subsetting Recycling can be used in a clever way to simplify code. Subsetting If we want to keep every third element of a vector we can do the following: Here the logical expression was expanded to the length of the vector. We can also perform comparisons using recycling: Here "bar" gets recycled. RemarksWhat is recycling in R Recycling (opens new window) is when an object is automatically extended in certain operations to match the length of another, longer object. For example, the vectorised addition results in the following: Because of the recycling, the operation that actually happened was: In cases where the longer object is not a multiple of the shorter one, a warning message is presented: Another example of recycling: |
Read Article
https://develop.horje.com/learn/1434/reference