Learn R Programming

digitTests (version 0.1.2)

extract_digits: Extraction of First or Last Digits

Description

This function extracts the first (and optionally second) or last digits in a vector.

Usage

extract_digits(x, check = 'first', include.zero = FALSE)

Arguments

x

a numeric vector.

check

location of the digits to extract. Can be first, firsttwo, or last.

include.zero

logical. Whether to include the digit zero in the output.

Value

A vector of first (and optionally second) or last digits.

Examples

Run this code
# NOT RUN {
set.seed(1)
x <- rnorm(100)

# Extract first digits (without zero)
extract_digits(x, check = 'first')

# Extract last digits (including zero)
extract_digits(x, check = 'last', include.zero = TRUE)

# }

Run the code above in your browser using DataLab