default_missing_column: Create a default value in a dataframe column if the column...

View source: R/default_column.R

default_missing_columnR Documentation

Create a default value in a dataframe column if the column doesn't already exist

Description

Create a default value in a dataframe column if the column doesn't already exist

Usage

default_missing_column(column, default_value = NA, env = dynGet("."))

Arguments

column

string name for column to default

default_value

default value for column, of length 1 or number of rows of dataframe

env

the environment (dataframe) in which to evaluate the column

Details

This function is designed to work from within a dplyr mutate call.

Value

the values of either the existing column, or the default_value if the column does not exist

Examples


library(dplyr)
mtcars %>% as_data_frame() %>% mutate(newcol=default_missing_column("newcol", 1))
mtcars %>% as_data_frame() %>% mutate(newcol=default_missing_column("newcol", 1:32))


qPharmetra/PMDatR documentation built on April 7, 2024, 5:42 p.m.