vec_obs() returns the number of observations in an object. This is
the length of a 1d vector, or the number of rows in a matrix or data frame.
There is no vctrs helper that retrieves the number of columns: as this
is a property of the type.
Usage
vec_obs(x)
Arguments
x
A vector
Value
An integer (or double for long vectors). Will throw an error
if x is not a vector.
Invariants
vec_obs(dataframe) == vec_obs(dataframe[[i]])
vec_obs(matrix) == vec_obs(matrix[, i, drop = FALSE])
vec_obs(vec_c(x, y)) == vec_obs(x) + vec_obs(y)
Details
vec_obs() is equivalent to NROW() but has a name that is easier to
pronounce, and throws an error when passed non-vector inputs.
See Also
vec_slice() for a variation of [ compatible with vec_obs().