[R] Selecting elements

Silvano Cesar da Costa @||v@no @end|ng |rom ue|@br
Thu Aug 19 22:39:52 CEST 2021


Hi,

I need to select 15 elements, always considering the highest values
(descending order) but obeying the following configuration:

3A - 4B - 0C - 3D or
2A - 5B - 0C - 3D or
3A - 3B - 2C - 2D

If I have, for example, 5 A elements as the highest values, I can only
choose 3 (first and third choice) or 2 (second choice) elements.

how to make this selection?


library(dplyr)

Var.1 = rep(LETTERS[1:4], 10)
Var.2 = sample(1:40, replace=FALSE)

data = data.frame(Var.1, Var.2)
(data = data[order(data$Var.2, decreasing=TRUE), ])

Elements = data %>%
  arrange(desc(Var.2))

Thanks,

Prof. Dr. Silvano Cesar da Costa
Universidade Estadual de Londrina
Centro de Ciências Exatas
Departamento de Estatística

Fone: (43) 3371-4346

	[[alternative HTML version deleted]]



More information about the R-help mailing list