Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:47:39+00:00 2026-06-09T23:47:39+00:00

Wasn’t sure how to title this, so please change it :) If I have

  • 0

Wasn’t sure how to title this, so please change it 🙂

If I have data like this and I want to trim it such that if there are more than one of any value in V5, then only keep the row with the highest value for V4. So for example, for V5=7200 there is row id 25 and row id 20 but I only want to keep row id 20 because its V4 is higher.

      V4   V5
29  9.94 5900
28 10.56 5100
27 11.34 6200
26 11.42 8300
25 13.16 7200
24 13.78 7500
23 14.16 6200
22 14.26 7500
21  14.6 7400
20 14.64 7200
19 15.86 8800

to:

      V4   V5
29  9.94 5900
28 10.56 5100
26 11.42 8300
23 14.16 6200
22 14.26 7500
21  14.6 7400
20 14.64 7200
19 15.86 8800

Is there a way to do this in a vectorized fashion or maybe some clever shortcut? If I have to do it for a lot of different matrices it could take a while with simple structures (for loops and the like).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:47:40+00:00Added an answer on June 9, 2026 at 11:47 pm
    df<-read.table(header=T,text="      V4   V5
    29  9.94 5900
    28 10.56 5100
    27 11.34 6200
    26 11.42 8300
    25 13.16 7200
    24 13.78 7500
    23 14.16 6200
    22 14.26 7500
    21  14.6 7400
    20 14.64 7200
    19 15.86 8800")
    
    
    df1<-df[with(df,order(V4,decreasing=T)),]
    df1<-df1[!duplicated(df1$V5),]
    > df1
          V4   V5
    19 15.86 8800
    20 14.64 7200
    21 14.60 7400
    22 14.26 7500
    23 14.16 6200
    26 11.42 8300
    28 10.56 5100
    29  9.94 5900
    
    df1<-df1[with(df1,order(V4)),] # if your order is important
    
    > df1
          V4   V5
    29  9.94 5900
    28 10.56 5100
    26 11.42 8300
    23 14.16 6200
    22 14.26 7500
    21 14.60 7400
    20 14.64 7200
    19 15.86 8800
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wasn't even sure how to title this right. I have a page that
I wasn't sure what to put into the title for this...please read on... I
I wasn't sure how to word this exactly. But I have a model that
I wasn't sure exactly how to phrase the question Title. I have this block
I wasn't even sure how to phrase this so you'll have to forgive me
I wasn't sure how to phrase this so the title is a bit cryptic.
I wasn't sure what to title this question. Here's my goal: On page one,
I wasn't sure how to word this question, so i'll just explain. I want
Wasn't sure how to write a good title for this question... :) I'm new
I wasn't sure if there was any good way of doing this. But I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.