Skip to content

Instantly share code, notes, and snippets.

@djq
Created August 2, 2017 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djq/633b41adf03978bf97dc528b2eee19d1 to your computer and use it in GitHub Desktop.
Save djq/633b41adf03978bf97dc528b2eee19d1 to your computer and use it in GitHub Desktop.
Table summary
# https://stackoverflow.com/questions/23629592/how-can-i-select-the-top-2-values-in-a-column-per-column-and-report-this-with-bo
t <- structure(c(0.333333333333333, 0.333333333333333, 0.333333333333333,
0.333333333333333, 0.333333333333333, 0.333333333333333, 0.166666666666667,
0.166666666666667, 0.166666666666667, 0.166666666666667, 0.166666666666667,
0.166666666666667, 0.166666666666667, 0.166666666666667, 0.166666666666667,
0.166666666666667, 0.166666666666667, 0.166666666666667, 0.333333333333333,
0.333333333333333, 0.333333333333333, 0.333333333333333, 0.333333333333333,
0.333333333333333), .Dim = c(6L, 4L), .Dimnames = list(c("1",
"2", "3", "4", "5", "6"), c("123", "124", "125", "126")))
# using apply & sort
apply(t,1,function(xx)head(names(sort(xx, decreasing=T)),4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment