grapes-rows-grapes: Binary Operator for Subsetting Rows While Preserving...

%rows%R Documentation

Binary Operator for Subsetting Rows While Preserving Attributes

Description

The binary operator %rows% returns the subset of specified rows for a data frame without removing column attributes.

Usage

x %rows% y

Arguments

x

A data frame.

y

An integer vector, logical vector, or character vector specifying the rows in x to keep.

Value

A data frame, a subset of x.

Author(s)

Kevin Potter

Examples

dtf <- data.frame(
  X1 = 1:4,
  X2 = LETTERS[1:4],
  X3 = c( TRUE, TRUE, FALSE, FALSE )
)
attributes( dtf$X1 ) <- list( Example_attr = "Integer" )
attributes( dtf$X2 ) <- list( Example_attr = "Character" )
attributes( dtf$X3 ) <- list( Example_attr = "Logical" )

# Each column has an attribute
str( dtf )

# Normal indexing removes attributes
str( dtf[1:2,] )

# Can use operator to avoid losing attributes
str( dtf %rows% 1:2 )


rettopnivek/camrprojects documentation built on March 26, 2024, 9:17 a.m.