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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:59:14+00:00 2026-06-02T10:59:14+00:00

I have 1 data.frame named A, there are 5000 columns in it. How can

  • 0

I have 1 data.frame named A, there are 5000 columns in it. How can I find columns in this data.frame that are equal to each other.

  • 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-02T10:59:16+00:00Added an answer on June 2, 2026 at 10:59 am

    As @John mentioned, there are problems with using duplicated. I would add that transposing the data.frame forces all the data into a same data type before it is even compared with duplicated. On an example, here is a data.frame:

    df <- data.frame( a = LETTERS[1:3],
                      b = 1:3,
                      c = as.character(1:3),
                      d = LETTERS[1:3],
                      e = 1:3,
                      f = 1:3)
    df
    #   a b c d e f
    # 1 A 1 1 A 1 1
    # 2 B 2 2 B 2 2
    # 3 C 3 3 C 3 3
    

    Note that column c is very similar to columns b, e, and f, but not identical because of the different types (character versus numeric). The solution suggested by @Jubbles would disregard these differences.

    Instead, it seems more appropriate to use the identical function on the columns of your data.frame. You can compare columns two-by-two using outer:

    are.cols.identical <- function(col1, col2) identical(df[,col1], df[,col2])
    identical.mat      <- outer(colnames(df), colnames(df),
                                FUN = Vectorize(are.cols.identical))
    identical.mat
    # [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
    # [1,]  TRUE FALSE FALSE  TRUE FALSE FALSE
    # [2,] FALSE  TRUE FALSE FALSE  TRUE  TRUE
    # [3,] FALSE FALSE  TRUE FALSE FALSE FALSE
    # [4,]  TRUE FALSE FALSE  TRUE FALSE FALSE
    # [5,] FALSE  TRUE FALSE FALSE  TRUE  TRUE
    # [6,] FALSE  TRUE FALSE FALSE  TRUE  TRUE
    

    From here, you can use clustering to identify groups of identical columns (there may be better ways so if you know one, feel free to comment or even edit my answer.)

    library(cluster)
    distances <- as.dist(!identical.mat)
    tree      <- hclust(distances)
    cut       <- cutree(tree, h = 0.5)
    cut
    # [1] 1 2 3 1 2 2
    
    split(colnames(df), cut)
    # $`1`
    # [1] "a" "d"
    # 
    # $`2`
    # [1] "b" "e" "f"
    # 
    # $`3`
    # [1] "c"
    

    Edit 1: to disregard differences in floating point values, one can use

    are.cols.identical <- function(col1,col2) isTRUE(all.equal((df[,col1],df[,col2]))
    

    Edit 2: a more efficient method than clustering for grouping the names of identical columns is

    cut <- apply(identical.mat, 1, function(x)match(TRUE, x))
    split(colnames(df), cut)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large data frame (named z ) that looks like this: RPos
I have a data.frame with 2 columns: Node A, Node B. Each entry in
I have a data.frame in R that looks like this: score rms template aln_id
Suppose that you have a data frame with many rows and many columns. The
I have this huge data frame that has servernames, Date, CPU, memory as the
I have a semi-melted data frame that looks like this: head(final_melt) Group Source variable
In R I have a data frame with 9 named columns, describing experimental data.
I have two data.frame objects 'x' and 'ans1', there are 500 columns in 'x'
I have a data frame with two columns. First column contains categories such as
I have a data frame with gaps like this: Var1 Var2 Var3 1 NA

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.