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 8822043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:00:09+00:00 2026-06-14T06:00:09+00:00

I can’t figure out what is the difference between these two functions in R.

  • 0

I can’t figure out what is the difference between these two functions in R.
I have a data.frame, and I want to remove rows corresponding to duplicated values in a given column;

    Acc         Probe             Coord_homol
1   NR_004442.1 225541_at~122     391
2   NM_028059.2 241348_at~444     4642
3   NM_028059.2 241348_at~468     4666
4   NM_001114   212306_at~4357    5034
5   NM_010573.2 230472_at~402     1987
6   NM_029633.2 212306_at~4357    4289
7   NM_00108196 212306_at~4357    4292
8   NM_029891.2 205004_at~3421    2963
9   NM_029891.2 205004_at~3635    3173
10  NM_007892.2 221586_s_at~1356 1257
11  NR_036613.1 208672_s_at~829  1301
12  NR_036613.1 208673_s_at~1472 1854
13  NM_011078.3 212726_at~3872    5175
14  NM_011078.3 212726_at~3887    5190
15  NM_013915.3 207164_s_at~1523 2911

in this case, I would like to remove rows 7 because the probe is the same as in row 6 (rows with same probes do not have to be successive ones).

I first tried unique(), and later found duplicated.
but if the following command

dat[!duplicated(dat$probe),]

dat[unique(dat$probe),]

give the same number of lines in the resulting data.frame, the results are not the same.

I tried on a much simpler case, like the following:

a simple data.frame:

> dat
   probe val
1    aaa  10
2    bbb  12
3    ccc  45
4    ddd  32
5    aaa  42
6    eee  10
7    fff  13
8    ccc  85
9    aaa  75
10   ddd  64

using !duplicated(): it seems to be what I want to do;

dat[!duplicated(dat$probe),]

  probe val
1   aaa  10
2   bbb  12
3   ccc  45
4   ddd  32
6   eee  10
7   fff  13

using unique():

dat[unique(dat$probe),]

I get:

 probe val
1   aaa  10
2   bbb  12
3   ccc  45
4   ddd  32
5   aaa  42
6   eee  10

Not what I want;

But what exactly unique() is doing ?

Thanks for your help.

  • 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-14T06:00:13+00:00Added an answer on June 14, 2026 at 6:00 am

    unique is returning a factor and the numeric levels of the factor are being used for indexing rather than the labels.

    uni <- unique(dat$probe)
    str(uni)
     Factor w/ 6 levels "aaa","bbb","ccc",..: 1 2 3 4 5 6
    

    It is like you are doing this:

    nums <- as.numeric(unique(dat$probe))
    dat[nums,]
      probe val
    1   aaa  10
    2   bbb  12
    3   ccc  45
    4   ddd  32
    5   aaa  42
    6   eee  10
    

    unique is returning a factor because we are putting a factor into it in this case. It doesn’t always return factors. For example, unique(as.character(dat$probe)) would return characters.

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

Sidebar

Related Questions

Can someone give me a clear, concise definition of the difference between a programming
Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can you tell me what is the difference between abstraction and information hiding in
Can someone please help me figure out why IE9 won't load my google map
Can anyone please explain to me how to figure out the type of the
Can I order my users in the database, so I don't have to say
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
Can anyone suggest how to underline the title of a UIButton ? I have
Can someone maybe tell me why this is not working? I have used echo

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.