aslength1 {essentials}R Documentation

Subset the First Element of a Vector

Description

Subset the first element of a vector.

Usage

aslength1(x)

Arguments

x

vector (or an object which can be coerced) with at least one element.

Details

Vectors of length one return themselves. Vectors of length greater than one return the first element with a warning. Vectors of length zero raise an error. If x is a vector (determined by is.vector), names will be preserved.

Value

A vector of length 1.

Examples

aslength1(1)
aslength1(1:10)
try(aslength1(integer(0)))

[Package essentials version 0.1.0 Index]