Learn R Programming

tidysq (version 1.2.3)

sqextract: Extract parts of a sq object

Description

Operator to extract subsets of sq objects.

Value

sq object of the same type as the input, containing extracted elements

Arguments

x

[sq]
An object this function is applied to.

i, j, ...

[numeric || logical]
Indices specifying elements to extract.

Details

This function follows vctrs-package conventions regarding argument interpretation for indexing vectors, which are a bit stricter that normal R conventions, for example implicit argument recycling is prohibited. Subsetting of the sq object does not affect its attributes (class and alphabet of the object). Attempt to extract elements using indices not present in the object will return an error.

See Also

Functions from utility module: ==.sq(), get_sq_lengths(), is.sq(), sqconcatenate

Examples

Run this code
# Creating object to work on:
sq_unt <- sq(c("AHSNLVSCTK$SH%&VS", "YQTVKA&#BSKJGY",
               "IAKVGDCTWCTY>", "AVYI#VSV&*DVGDJCFA"))

# Subsetting using numeric vectors
# Extracting second element of the object:
sq_unt[2]

# Extracting elements from second to fourth:
sq_unt[2:4]

# Extracting all elements except the third:
sq_unt[-3]

# Extracting first and third element:
sq_unt[c(1,3)]

# Subsetting using logical vectors
# Extracing first and third element:
sq_unt[c(TRUE, FALSE, TRUE, FALSE)]

# Subsetting using empty vector returns all values:
sq_unt[]

# Using NULL, on the other hand, returns empty sq:
sq_unt[NULL]

Run the code above in your browser using DataLab