Skip to content
Prev 388820 / 398502 Next

Selecting elements

Hallo

I am confused, maybe others know what do you want but could you be more specific?

Let say you have such data
set.seed(123)
Var.1 = rep(LETTERS[1:4], 10)
Var.2 = sample(1:40, replace=FALSE)
data = data.frame(Var.1, Var.2)

What should be the desired outcome?

You can sort
data <- data[order(data$Var.2, decreasing=TRUE), ]
and split the data
$A
 [1] 38 35 32 31 30 22 11  8  2  1

$B
 [1] 39 28 25 23 16 15  7  6  5  4

$C
 [1] 40 36 29 26 21 19 18 14 10  9

$D
 [1] 37 34 33 27 24 20 17 13 12  3

T inspect highest values. But here I am lost. As C is first and fourth biggest value, you follow third option and select 3 highest A, 3B 2C and 2D?

Or I do not understand at all what you really want to achieve.

Cheers
Petr