Interactive Tables
Table Filter
Keep Matching Rows
Interactive tables often filter rows from user controls. The same idea can be modeled with logical indexing.
Program
Play the script to change the minimum score and see which rows remain visible.
table_filter.R
name <- c("Ada", "Bo", "Chen", "Dia")
score <- c(91, 84, 88, 76)
min_score <-
keep <- score >= min_score
rows <- paste(name[keep], score[keep], sep = "=")
label <- paste(rows, collapse = ",")
cat(label, "\n", sep = "")
name <- c("Ada", "Bo", "Chen", "Dia")
score <- c(91, 84, 88, 76)
min_score <-
keep <- score >= min_score
rows <- paste(name[keep], score[keep], sep = "=")
label <- paste(rows, collapse = ",")
cat(label, "\n", sep = "")
name <- c("Ada", "Bo", "Chen", "Dia")
score <- c(91, 84, 88, 76)
min_score <-
keep <- score >= min_score
rows <- paste(name[keep], score[keep], sep = "=")
label <- paste(rows, collapse = ",")
cat(label, "\n", sep = "")
logical filter
`score >= min_score` creates one keep/drop value per row.
row subset
`name[keep]` keeps names whose score passed the filter.
display row
`paste(name[keep], score[keep], sep = "=")` formats visible rows.