Learn R Programming

wrangle (version 0.6.4)

constant.data.frame: Identify Constant Features of a Data Frame

Description

Returns columns of a data.frame whose values do not vary within subsets defined by columns named in .... Defaults to groups(x) if none supplied, or all columns otherwise.

Usage

# S3 method for data.frame
constant(x, ...)

Value

data.frame (should be same class as x)

Arguments

x

object

...

optional grouping columns (named arguments are ignored)

See Also

Other constant: constant()

Examples

Run this code
library(dplyr)
constant(Theoph)                      # data frame with 0 columns and 1 row
constant(Theoph, Subject)             # Subject Wt Dose Study
Theoph$Study <- 1
constant(Theoph)                      # Study
constant(Theoph, Study)               # Study
constant(Theoph, Study, Subject)      # Subject Wt Dose Study
Theoph <- group_by(Theoph, Subject)
constant(Theoph)                      # Subject Wt Dose Study
constant(Theoph, Study)               # Study
foo <- data.frame(x = 1)
foo <-  group_by(foo, x)
class(foo) <- c('foo', class(foo))
stopifnot(identical(class(foo), class(constant(foo))))

Run the code above in your browser using DataLab