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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:09:59+00:00 2026-05-23T04:09:59+00:00

Does anyone know how to remove an entire column from a data.frame in R?

  • 0

Does anyone know how to remove an entire column from a data.frame in R? For example if I am given this data.frame:

> head(data)
   chr       genome region
1 chr1 hg19_refGene    CDS
2 chr1 hg19_refGene   exon
3 chr1 hg19_refGene    CDS
4 chr1 hg19_refGene   exon
5 chr1 hg19_refGene    CDS
6 chr1 hg19_refGene   exon

and I want to remove the 2nd column.

  • 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-05-23T04:10:00+00:00Added an answer on May 23, 2026 at 4:10 am

    You can set it to NULL.

    > Data$genome <- NULL
    > head(Data)
       chr region
    1 chr1    CDS
    2 chr1   exon
    3 chr1    CDS
    4 chr1   exon
    5 chr1    CDS
    6 chr1   exon
    

    As pointed out in the comments, here are some other possibilities:

    Data[2] <- NULL    # Wojciech Sobala
    Data[[2]] <- NULL  # same as above
    Data <- Data[,-2]  # Ian Fellows
    Data <- Data[-2]   # same as above
    

    You can remove multiple columns via:

    Data[1:2] <- list(NULL)  # Marek
    Data[1:2] <- NULL        # does not work!
    

    Be careful with matrix-subsetting though, as you can end up with a vector:

    Data <- Data[,-(2:3)]             # vector
    Data <- Data[,-(2:3),drop=FALSE]  # still a data.frame
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to remove Treeitems from a Treechildren node in ZK? I
Does anyone know of a method to remove all webapps deployed from .war files
does anyone know of a good regular expression to remove events from html. For
Does anyone know if it's possible to remove the topbar from a UITableView in
Does anyone know how to remove markup from the theme search box? It produces
Does anyone know how I can remove the address bar from the Android browser
Does anyone know why this never doesn't work: if !exists(g:removenumbchar) if a:type == remove
Does anyone know how to remove the Now button from the jquery timepicker add
Does anyone know how I would remove all leading zeros from a string. var
Does anyone know how I can remove links from the top menu using local.xml.

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.