Skip to contents

This function drops undefined values in a data frame by replacing them with NA.

Usage

drop_undefined(df, vars, vals_undefined = c("pnta", "dnk"), suffix = NULL)

Arguments

df

A data frame to modify.

vars

A character vector of variable names to check for undefined values.

vals_undefined

A character vector of values to consider as undefined. Defaults to c("pnta", "dnk").

suffix

A character scalar or an empty string to append to the variable names. Defaults to NULL.

Value

The modified data frame with undefined values replaced by NA. If suffix is NULL or an empty string, variables vars are modified; otherwise, new variables are added with suffix.

Examples

# Create a sample data frame
df <- data.table::data.frame(x = c("a", "b", "pnta", "dnk", "e"), y = c("a", "b", "c", "d", "e"))
#> Error: 'data.frame' is not an exported object from 'namespace:data.table'

# Define variables and undefined values
vars <- c("x", "y")
vals_undefined <- c("pnta", "dnk")

# Drop undefined values
result <- drop_undefined(df, vars, vals_undefined)
#> Error in drop_undefined(df, vars, vals_undefined): Assertion on 'df' failed: Must be of type 'data.frame', not 'closure'.
print(result)
#> Error: object 'result' not found