dropvar: Drop variables and/or observations

View source: R/data-edit.R

dropvarR Documentation

Drop variables and/or observations

Description

Drops variables or observations from an explicit data frame or active data.

Usage

dropvar(..., data = NULL, obs = NULL)

Arguments

...

Variable selectors. For backward compatibility, an explicit data frame may be the first unnamed argument.

data

Optional explicit data frame object.

obs

Optional observations to drop.

Value

The edited data frame invisibly.

Examples

d <- data.frame(id = 1:4, age = c(10, 20, NA, 40), note_kt = letters[1:4])
usedf(d, quiet = TRUE)
dropvar("*_kt")
dropvar(obs = age < 18)

# Extended usage examples

d <- data.frame(id = 1:5, age = c(10, 20, NA, 40, 50),
                temp_a = 1:5, temp_b = 6:10, note = letters[1:5])

# Drop one or more variables
d1 <- d; dropvar(d1, note)
d2 <- d; dropvar(d2, temp_a, temp_b)

# Drop variables with a wildcard
d3 <- d; dropvar(d3, "temp_*")

# Drop observations satisfying a condition
d4 <- d; dropvar(d4, obs = age < 18)
d5 <- d; dropvar(d5, obs = missing(age))

# Drop variables and observations together
d6 <- d; dropvar(d6, note, obs = age < 18)

# Active-data syntax
usedf(d, quiet = TRUE); dropvar("temp_*"); dropvar(obs = missing(age))


R4VN documentation built on Sept. 30, 2026, 5:13 p.m.