n_obs: Return the number of observations

View source: R/n-obs.R

n_obsR Documentation

Return the number of observations

Description

Returns the number of observations of a vector or data.frame. It uses vctrs::vec_size() under the hood.

Usage

n_obs(x, names = TRUE)

Arguments

x

vector or data.frame

names

logical; If TRUE the result is a named vector named "n_obs", else it is just the number of observations.

Value

number of observations

Note

You cannot use n_obs with features counting the key variable like so - features(heights, country, n_obs). Instead, use any other variable.

Examples

n_obs(iris)
n_obs(1:10)
add_n_obs(heights)
heights %>%
  features(height_cm, n_obs) # can be any variable except id, the key.

brolgar documentation built on June 22, 2024, 11:24 a.m.