Skip to content
Prev 361060 / 398506 Next

Choosing rows

Hello,

First of all, it's better to post data using ?dput. Below, I give an  
example of that? in the lines structure(...).
dat <-
structure(list(rs = c("?? rs941873? ", "?? rs634552? ", "?? rs11107175? ",
"?? rs12307687? ", "?? rs3917155? ", "?? rs1600640? ", "?? rs2871865? ",
"?? rs2955250? ", "?? rs228758? ", "?? rs224333? ", "?? rs4681725? ",
"?? rs7652177? ", "?? rs925098? ", "?? rs1662837? ", "?? rs10071837? "
), n0 = c(81139462, 75282052, 94161719, 47175866, 76444685, 84603034,
99194896, 61959740, 42148205, 34023962, 56692321, 171969077,
17919811, 82168889, 33381581), Pvalue = c(1.52e-07, 0.108, 0.0285,
0.123, 0.68, 0.000275, 0.0709, 0.0317, 0.0772, 0.021, 0.000445,
0.000634, 5.55e-09, 8.66e-05, 0.000574), V1 = c("rs941873", "rs941873",
"rs941873", "rs12307687", "rs941873", "rs12307687", "rs12307687",
"rs12307687", "rs12307687", "rs10071837", "rs10071837", "rs10071837",
"rs925098", "rs925098", "rs925098")), .Names = c("rs", "n0",
"Pvalue", "V1"), row.names = c(NA, -15L), class = "data.frame")

Now, if I understand correctly, the following might do what you want.

tmp <- split(dat[, "Pvalue"], dat[, "V1"])
idx <- unlist(lapply(tmp, function(x) x == min(x)))[order(order(dat[, "V1"]))]
rm(tmp)
result <- dat[idx, ]
result

Hope this helps,

Rui Barradas
?

Citando oslo via R-help <r-help at r-project.org>:
?