wide_to_long: Convert Metadata from Wide to Long Format

View source: R/wide_to_long.R

wide_to_longR Documentation

Convert Metadata from Wide to Long Format

Description

This function transforms a metadata data frame from a wide format to a long format. The goal is to consolidate spanning variables into a single column, making the table easier to handle regardless of the number of spanning variables described.

Usage

wide_to_long(df_metadata)

Arguments

df_metadata

A data frame in wide format. It must contain columns starting with "spanning" and "hrc_spanning", representing spanning variables and their hierarchical counterparts.

Value

A data frame in long format. The resulting data frame contains two columns:

  • spanning: The consolidated values of the spanning variables.

  • Any additional columns retained from the original data frame. Rows where the names of "spanning" and "hrc_spanning" do not match, or where spanning values are NA, are filtered out.

Examples

## Not run: 
data(metadata_pizza_lettuce)

# View the structure of the original data
str(metadata_pizza_lettuce)

# Convert to long format
metadata_pizza_lettuce_long <- wide_to_long(metadata_pizza_lettuce)

# View the structure of the resulting data
str(metadata_pizza_lettuce_long)

## End(Not run)


InseeFrLab/rtauargus documentation built on Feb. 25, 2025, 6:32 a.m.