ff_spread_dual: Spread columns when there are two value columns that need to...

View source: R/cleaning.R

ff_spread_dualR Documentation

Spread columns when there are two value columns that need to be retained.

Description

The 'spread' function only takes one value column. But, we often need to spread a dataset into wide-form, but with two value columns. A example is when we want to spread a dataset, but keep the estimate and standard error columns. This function allows users to spread a dataset and keep two value columns.

Usage

ff_spread_dual(df, key, value_a, value_b, join_cols)

Arguments

df

Dataframe of ACS data

key

Key column in dataframe as string (the column with the information we want to spread on)

value_a

First value column we want to keep as string

value_b

Second value column we want to keep as string

join_cols

Each value column is spread individually, and then both new spread datasets are joined. 'join_cols' signifies which column to join the to datasets on.

Value

A dataframe with seperate columns for each of the values spread on, and value_a and value_b. The final dataframe will contain all the join columns and value columns totaling the number of items to spread on times two (two different values that are kept when spreading).

Examples

ff_spread_dual(total, 'description', 'estimate', 'se', c('geo_description', 'year'))


forsythfuture/FFtools documentation built on April 5, 2022, 10:02 p.m.