# 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