Performance Awareness
Vector Filter
Count Work Kept
Vectorized filters express the whole selection rule at once instead of one item at a time.
Program
Play the script to change the threshold and see how many values are kept.
vector_filter.R
threshold <-
values <- c(4, 9, 12, 18)
kept <- values[values >= threshold]
count <- length(kept)
label <- paste("kept", count, sep = ":")
cat(label, "\n", sep = "")
threshold <-
values <- c(4, 9, 12, 18)
kept <- values[values >= threshold]
count <- length(kept)
label <- paste("kept", count, sep = ":")
cat(label, "\n", sep = "")
threshold <-
values <- c(4, 9, 12, 18)
kept <- values[values >= threshold]
count <- length(kept)
label <- paste("kept", count, sep = ":")
cat(label, "\n", sep = "")
vectorized rule
`values >= threshold` creates one logical decision per value.
subset
The bracket expression keeps all matching values in one statement.
work summary
Counting kept values summarizes how much data remains.