shadow_long: Reshape shadow data into a long format

shadow_longR Documentation

Reshape shadow data into a long format

Description

Once data is in nabular form, where the shadow is bound to the data, it can be useful to reshape it into a long format with the shadow columns in a separate grouping - so you have variable, value, and variable_NA and value_NA.

Usage

shadow_long(shadow_data, ..., fn_value_transform = NULL, only_main_vars = TRUE)

Arguments

shadow_data

a data.frame

...

bare name of variables that you want to focus on

fn_value_transform

function to transform the "value" column. Default is NULL, which defaults to as.character. Be aware that as.numeric may fail for some instances if it cannot coerce the value into numeric. See the examples.

only_main_vars

logical - do you want to filter down to main variables?

Value

data in long format, with columns variable, value, variable_NA, and value_NA.

Examples


aq_shadow <- nabular(airquality)

shadow_long(aq_shadow)

# then filter only on Ozone
shadow_long(aq_shadow, Ozone)

shadow_long(aq_shadow, Ozone, Solar.R)

# ensure `value` is numeric
shadow_long(aq_shadow, fn_value_transform = as.numeric)
shadow_long(aq_shadow, Ozone, Solar.R, fn_value_transform = as.numeric)



naniar documentation built on May 29, 2024, 1:43 a.m.