Description Arguments Value Usage Details Author(s) Examples
This function guarantees a vector of length > 1 as the return value of an indexing operation.
v |
A sequence |
idx |
The index of the element to extract |
Either the value of x[idx] or NA for invalid index values
item(v, idx)
Standard R indexing yields different results depending on the input. When either an empty vector or a NULL is passed to the indexing operator, an empty vector is returned. However, if the index is NA, the return value will be a vector of NAs having the same length as the original vector. This inconsistent behavior requires special handling whenever the index value is computed dynamically.
This function is designed to create a consistent return value for a bad index value, which is defined as NULL, NA, vector of length 0. If any of these values are used as the index, then NA is returned instead of an empty vector.
Brian Lee Yung Rowe
1 2 3 4 5 6 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.