0

As the image shows, I calculate the pt value and rank it. Then I used which function to find the index of the largest value pt. Since there are two values of 1, I need to find the first index, so I use min function, and it does give me value of 4. Then I want to delete the 4th value in pt, and I suppose to see 0.85, 0.713, 0.666, and 1, because I only want to delete one number. However, it somehow deletes two number stead. What is the reason, and how can I fix it?

sample code

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Legend
  • 1
  • 6
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Don't post code as an image. If you just want to delete item `i`, then do `pt[-i]` – MrFlick Feb 09 '19 at 02:41
  • 1
    Your last line calls all elements in pt that are NOT equal to pt[i]. That is all elements that are not pt[4] which is 1.0. This is why it returns everything but 1.0. MrFlick is correct – twb10 Feb 09 '19 at 03:11

1 Answers1

2

After i is calculated, just do

pt <- pt[-i]

Then type pt in the console and you will have the desired output.

Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/22162487) – Chris Gong Feb 09 '19 at 17:07
  • 1
    @ChrisGong - yes it does. We have a new contributor who didn't properly format the code. Fixed now :) – Rich Scriven Feb 09 '19 at 17:26
  • PS - you can hit the "edit" button and see how I formatted the code. And there is a link to markdown help in the upper right corner of the editing box. – Rich Scriven Feb 09 '19 at 17:30
  • @RichScriven my apologies, this was definitely a mistake on my part – Chris Gong Feb 09 '19 at 18:41