Skip to content
Back to formatted view

Raw Message

Message-ID: <CAMaZ2WApiOFxNj9qY4Gt7=COx=UoWdshyV-FebfpTc+fQ2aruA@mail.gmail.com>
Date: 2021-08-19T20:39:52Z
From: Silvano
Subject: Selecting elements

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]]