%rows% | R Documentation |
The binary operator %rows% returns the subset of specified rows for a data frame without removing column attributes.
x %rows% y
x |
A data frame |
y |
An integer vector, logical vector, or character vector specifying the rows in x to keep. |
A data frame.
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 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.