Learn R Programming

dataset (version 0.3.1)

head.dataset: Return the first or last parts of a dataset object

Description

Returns the first or last parts of a dataset. Both head() and tail() are generic functions.

Usage

# S3 method for dataset
head(x, n = 6L, ...)

# S3 method for dataset tail(x, n, keepnums = FALSE, ...)

Value

A subsetted dataset, the first or last parts of a dataset object.

Arguments

x

A dataset object created with dataset.

n

an integer vector of length up to dim(x) (or 1, for non-dimensioned objects). A logical is silently coerced to integer. Values specify the indices to be selected in the corresponding dimension (or along the length) of the object. A positive value of n[i] includes the first/last n[i] indices in that dimension, while a negative value excludes the last/first abs(n[i]), including all remaining indices. NA or non-specified values (when length(n) < length(dim(x))) select all indices in that dimension. Must contain at least one non-missing value.

...

Ignored.

keepnums

in each dimension, if no names in that dimension are present, create them using the indices included in that dimension. Ignored if dim(x) is NULL or its length 1.

See Also

subsetting

Examples

Run this code

# Subsetting the top n rows (observations)
head(iris_dataset, n=3)

# Subsetting the last n rows (observations)
tail(iris_dataset, 3)

Run the code above in your browser using DataLab