[R] get maximum 3 rows by column elements in data frame
Ragia Ibrahim
ragia11 at hotmail.com
Mon Nov 9 11:55:27 CET 2015
Dear group,
I have the following data freame
dput(df_all_nodes)
structure(list(Measure_id = c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1,
2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2,
3, 4, 5, 1, 2, 3, 4, 5), i = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7), j = c(1, 1, 1, 1, 1, 3, 3, 3, 3,
3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 5, 5, 5, 5, 5), value = c(1.5, 2, 1, 0, 2, 2,
1.5, 0, 0, 1, 1, 2, 0, 1, 2, 2, 0.5, 1, 0, 2, 2, 1.5, 0, 0, 1,
1.5, 2.5, 0, 1, 2, 1.5, 1, 0, 0, 1, 1, 2, 0, 0, 1), rank = c(0.75,
1, 1, 0, 1, 1, 0.75, 0, 0, 0.5, 0.5, 1, 0, 1, 1, 1, 1, 1, NaN,
1, 1, 0.6, NaN, 0, 0.5, 0.75, 1, NaN, 1, 1, 1, 0.5, NaN, NaN,
1, 0.666666666666667, 1, NaN, NaN, 1)), .Names = c("Measure_id",
"i", "j", "value", "rank"), row.names = c(NA, 40L), class = "data.frame")
>
I want to get maximum 3 rows in each group of Measure_id. e.g. for measure_id 1 get the max ranks (select the max for each measure depending on the rank column).
how to do that
Best regards,
Ragia
More information about the R-help
mailing list