'How can I use subsets to separate stocks into groups in my R code as a constraint for a stock portfolio? Any thoughts would be much appreciated

assets <- c("1",  "2", "3", "4")
port_spec <- add.constraint(portfolio = port_spec, type = "group", groups = list(c(1, 2, 3), 4), group_labels = c("Grupa A", "Grupo B"), group_pos = c(2,1))


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source