Learn R Programming

dataset (version 0.3.1)

subsetting: Subsetting datasets

Description

Accessing columns, rows, or cells via $, [[, or [ is mostly similar to regular data frames. However, the

  • [ always returns a similar dataset by default, even if only one column is accessed. The title is modified to from 'Original Title' to 'Original Title [subset]'

  • [[ always returns a vector.

  • $ always returns a vector.

Usage

# S3 method for dataset
[(x, i, j, drop = FALSE, ...)

# S3 method for dataset $(x, name)

# S3 method for dataset [[(x, i, j, ..., exact = TRUE)

Arguments

x

A dataset object created with dataset.

i, j

Row and column indices. If j is omitted, i is used as column index.

drop

logical. If TRUE the result is coerced to the lowest possible dimension. The default is to drop if only one column is left, but not to drop if only one row is left.

...

Ignored.

name

A name or a string.

exact

Ignored, with a warning.

See Also

head.dataset

Examples

Run this code
# Subsetting single columns:
iris_dataset[, "Species"]

# Subsetting single column to vector:
iris_dataset$Species
iris_dataset[, "Species"]

# Subsetting a single cell in tabular data:
iris_dataset[[1,2]]

#Subsetting a variable into a vector.
iris_dataset$Species

Run the code above in your browser using DataLab