View source: R/default_column.R
default_missing_column | R Documentation |
Create a default value in a dataframe column if the column doesn't already exist
default_missing_column(column, default_value = NA, env = dynGet("."))
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 |
This function is designed to work from within a dplyr mutate call.
the values of either the existing column, or the default_value if the column does not exist
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.