cj_df: Create a "cj_df" data frame

Description Usage Arguments Value Examples

View source: R/cj_df.R

Description

A simple data frame extension that preserves attributes during subsetting operations.

Usage

1
2
3
4
5
6
7
cj_df(x)

## S3 method for class 'data.frame'
cj_df(x)

## S3 method for class 'cj_df'
x[i, j, drop = FALSE]

Arguments

x

A data frame

i

See [.data.frame

j

See [.data.frame

drop

Ignored.

Value

An data frame with additional “cj_df” class, which has subsetting methods that preserve variables attributes.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
x1 <- data.frame(a = 1:3, b = 4:6)
attr(x1$a, "label") <- "Variable A"

# cj_df() returns a data frame
inherits(x1, "data.frame")
class(x1)

# attributes dropped for data frames
attr(x1[1:2,]$a, "label")

# attributes preserved with a cj_df
attr(cj_df(x1)[1:2,]$a, "label")

cregg documentation built on July 8, 2020, 6:57 p.m.