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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:51:18+00:00 2026-06-14T02:51:18+00:00

I would like to determine whether a list contains any duplicate elements, while considering

  • 0

I would like to determine whether a list contains any duplicate elements, while considering permutations as equivalent. All vectors are of equal length.

What is the most efficient way (shortest running time) to accomplish this?

## SAMPLE DATA
a  <- c(1, 2, 3)
b  <- c(4, 5, 6)
a.same <- c(3, 1, 2)

## BOTH OF THSE LISTS SHOULD BE FLAGGED AS HAVING DUPLICATES
myList1 <- list(a, b, a)
myList2 <- list(a, b, a.same)


# CHECK FOR DUPLICATES
anyDuplicated(myList1) > 0  # TRUE
anyDuplicated(myList2) > 0  # FALSE, but would like true. 

For now I am resorting to sorting each member of the list before checking for duplicates

anyDuplicated( lapply(myList2, sort) ) > 0

I am wondering if there is a more efficient alternative. Also, in the ?duplicated documentation, it indicates “Using this for lists is potentially slow”. Are there other functions better suited for lists?

  • 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-14T02:51:20+00:00Added an answer on June 14, 2026 at 2:51 am

    What about this…?

    a  <- c(1, 2, 3)
    b  <- c(4, 5, 6)
    a.same <- c(3, 1, 2)
    myList1 <- list(a, b, a)
    myList2 <- list(a, b, a.same)
    
    # For exact duplicated values: List1
    DF1 <- do.call(rbind, myList1)  # From list to data.frame
    ind1 <- apply(DF1, 2, duplicated) # logical matrix for duplicated values
    DF1[ind1] # finding duplicated values  
    [1] 1 2 3
    
    # For permutations: List2
    DF2 <- do.call(rbind, myList2)
    ind2 <- apply(apply(DF2, 1, sort), 1, duplicated)
    DF2[ind2] # duplicated values
    [1] 3 1 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to (quickly) determine if one array contains all the elements of
Let's say I have the string Hey . I would like to determine all
I would like to know how to determine whether string is valid file path.
I would like to use a unique identifier to determine whether my application moved
I would like to automatically determine whether given object is Combinatorica or Mathematica 8.0
Would like to determine via code whether the voice channel on an Android is
I would like my GWT program to be able to determine whether it's in
I would like to determine whether a string S has a substring MYSUBSTRING preceded
I would like to determine whether a particular string appears in a column in
I would like to determine what the long url of a short url is.

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.