1

I have gotten the matrix in R as shown below. If I use the command

rows <- which(sim_results == min(sim_results))

It will return 17 and 854.

Now I would like to retrieve the top 10 records sorted by scores. i.e. to get values from 17 to 630 shown in the matrix.

I tried to do the coding as per below, however it didn't retrieve from 17 to 630 but retrieved values as highlighted. Anything I did wronlgy?

enter image description here enter image description here

user1805430
  • 109
  • 1
  • 8
  • 20
  • 2
    `head(sim_results, 10)`. – Rui Barradas Nov 07 '17 at 17:34
  • 1
    use the `order` and then do as @RuiBarradas suggested – akrun Nov 07 '17 at 17:35
  • 3
    Please save the rstudio tag for rstudio specific problems, like if your code works on the command line but not in RStudio. – Gregor Thomas Nov 07 '17 at 17:35
  • Or `sim_results[1:10, ]`. Looks like your data is already ordered... – Gregor Thomas Nov 07 '17 at 17:37
  • Hi, Please refer to my rephrased question.. – user1805430 Nov 07 '17 at 17:42
  • If you just want the row names, then instead of `head(sim_results, 10)` you can do `head(rownames(sim_results), 10)` or `rownames(sim_results)[1:10]`. Replace `sim_results` with `sim_results[order(sim_results$V1), ]` if you want to (re?)sort it first. – Gregor Thomas Nov 07 '17 at 21:54
  • Also, from your syntax it is evident that you have a `data.frame`, not a `matrix`. These differences matter. I would strongly encourage you to [make copy/pasteable reproducible examples in the future with `dput()` or simulated data, this link will explain how.](https://stackoverflow.com/q/5963269/903061) Pictures of data are really terrible. – Gregor Thomas Nov 07 '17 at 21:56

0 Answers0