| select_top_k_scores_by_group | R Documentation |
For each date, choose the top k symbols within each group based on a
score panel. Returns a logical selection panel aligned to the input.
select_top_k_scores_by_group(scores, k, group_map, max_per_group = 3L)
scores |
Wide score panel ( |
k |
Positive integer: number of symbols to select per group. |
group_map |
Named character vector or 2-column data.frame
( |
max_per_group |
Integer cap per group (default |
Group membership comes from group_map (symbol -> group).
Selection is computed independently by group on each date.
Ties follow the ordering implied by order(..., method = "radix").
Logical selection panel (Date + symbols) where TRUE marks
selected symbols.
set.seed(42)
scores <- data.frame(
Date = as.Date("2020-01-01") + 0:1,
A = runif(2), B = runif(2), C = runif(2), D = runif(2), E = runif(2), F = runif(2)
)
gmap <- data.frame(Symbol = c("A","B","C","D","E","F"),
Group = c("G1","G1","G2","G2","G3","G3"))
sel <- select_top_k_scores_by_group(scores, k = 4, group_map = gmap, max_per_group = 2)
head(sel)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.