Skip to contents

Select top-N responses above a threshold

Usage

select_threshold(prob_mat, threshold, N)

Arguments

prob_mat

Numeric matrix of probabilities; rownames are response IDs, colnames are predictors/groups.

threshold

Numeric scalar: probability cutoff for selection.

N

Integer scalar: maximum number of positive selections per column.

Value

Integer matrix (0/1) with same dimnames as prob_mat.

Examples

mat <- matrix(runif(12), nrow = 4, dimnames = list(paste0("resp", 1:4), c("A", "B", "C")))
select_threshold(mat, threshold = 0.5, N = 2L)
#>       A B C
#> resp1 0 1 1
#> resp2 0 0 1
#> resp3 1 1 0
#> resp4 1 0 0