Filter the active component of a tidymatrix object. When rows are active, filters row_data and the corresponding matrix rows. When columns are active, filters col_data and the corresponding matrix columns. Cannot filter when matrix is active.
Usage
# S3 method for class 'tidymatrix'
filter(.data, ..., .preserve = FALSE)Examples
library(dplyr, warn.conflicts = FALSE)
tm <- tidymatrix(big5_responses, big5_respondents, big5_items)
# Keep respondents aged 60 or over; the matrix rows follow
tm |>
activate(rows) |>
filter(age >= 60)
#> # A tidymatrix: 44 x 30 matrix
#> # Active: rows
#> #
#> # Row data: 44 rows x 8 columns
#> # Column data: 30 rows x 5 columns
#> #
#> # Active data (rows):
#> respondent_id age gender education occupation country life_satisfaction
#> 1 R003 66 Male Bachelor Office EE 6
#> 2 R006 62 Female Basic Service/Manual EE 4
#> 3 R011 61 Female Bachelor Professional LV 7
#> 4 R017 67 Female Secondary Retired LV 4
#> 5 R019 67 Male PhD Professional EE 7
#> 6 R026 64 Female Secondary Service/Manual EE 6
#> completion_min
#> 1 6.3
#> 2 11.6
#> 3 5.9
#> 4 14.7
#> 5 9.3
#> 6 10.6
# Keep only the Extraversion items
tm |>
activate(columns) |>
filter(trait == "Extraversion")
#> # A tidymatrix: 400 x 6 matrix
#> # Active: columns
#> #
#> # Row data: 400 rows x 8 columns
#> # Column data: 6 rows x 5 columns
#> #
#> # Active data (columns):
#> item_id trait reversed item_text position
#> 1 E1 Extraversion FALSE I feel comfortable around people. 1
#> 2 E2 Extraversion FALSE I start conversations. 6
#> 3 E3 Extraversion FALSE I enjoy being part of a lively crowd. 11
#> 4 E4 Extraversion FALSE I make friends easily. 16
#> 5 E5 Extraversion TRUE I keep in the background. 21
#> 6 E6 Extraversion TRUE I have little to say to strangers. 26