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

  • Home
  • SEARCH
  • 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 8950011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:21:05+00:00 2026-06-15T13:21:05+00:00

I’ve got this dataframe: Name Country Gender Age 1 John GB M 25 2

  • 0

I’ve got this dataframe:

    Name    Country Gender  Age
1   John      GB      M     25
2   Mark      US      M     35
3   Jane      0       0      0
4   Jane      US      F     30
5   Jane      US      F      0
6   Kate      GB      F     18

As you can see the value “Jane” appears 3 times. What I want to do is to deduplicate the list based on the variable “Name” but because the rest of the columns are important to me, I want to keep the rows that have the most information in them. For example if I was to deduplicate the above file in excel, it would keep the first value of “Jane” and delete all the other ones. But the first value of “Jane” (row no3) has got missing information in the other columns.

So in other words I want to deduplicate the list by “Name” but add a criteria to keep the rows that have any other value different from “0” in the column “Age”. This way the result I would get would be this:

    Name    Country Gender  Age
1   John       GB     M     25
2   Mark       US     M     35
3   Jane       US     F     30
4   Kate       GB     F     18

I have tried this

file3 <- file1[!duplicated(file1$Name),]

But like excel it keeps the value of “Jane” that has no usable information in the other columns.

How do I sort the rows based on column “Age” in a Z-A order so that anything that has “0” will be on the bottom and will be removed when I deduplicate the list?

Cheers

David

  • 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-15T13:21:07+00:00Added an answer on June 15, 2026 at 1:21 pm

    Try this trick

    ind <- with(DF, 
            Country !=0 &
            Gender %in% c('F', 'M') &
            Age !=0)
    
    DF[ind, ]
      Name Country Gender Age
    1 John      GB      M  25
    2 Mark      US      M  35
    4 Jane      US      F  30
    6 Kate      GB      F  18
    

    So far it works well and produces your desired output

    EDIT

     library(doBy)
        orderBy(~ -Age+Name, DF) # Sort decreasingly by Age and Name
    
      Name Country Gender Age
    2 Mark      US      M  35
    4 Jane      US      F  30
    1 John      GB      M  25
    6 Kate      GB      F  18
    3 Jane       0      0   0
    5 Jane      US      F   0
    

    Or simply using Base functions:

    DF[order(DF$Age, DF$Name, decreasing = TRUE), ]
      Name Country Gender Age
    2 Mark      US      M  35
    4 Jane      US      F  30
    1 John      GB      M  25
    6 Kate      GB      F  18
    3 Jane       0      0   0
    5 Jane      US      F   0
    

    Now you can select by indexing the correct rows meeting your conditions, I really think the first part is better than these two lasts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.