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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:08:40+00:00 2026-06-11T15:08:40+00:00

I’m wondering if there is a good way to delete multiple columns over a

  • 0

I’m wondering if there is a good way to delete multiple columns over a few different data sets in R. I have a data set that looks like:

RangeNumber    Time    Value    Quality    Approval
          1    2:00        1          1           1
          2    2:05        4          2           1

And I want to delete everything but the Time and Value columns in my data sets. I’m “deleting” them by setting each column to NULL, e.x.: data1$RangeNumber <- NULL.

I’m going to have upwards of 16 or more data sets with identical column setups, and data sets are going to be numbered in incremental order, e.x.: data1, data2, data3, &c.

I’m wondering if a for loop that iterates through all of the data set columns is the best way to accomplish this, or — since I have read that R is slow at for loops– if there is an easier way to do this. I’m also wondering if I need to combine all of my data sets into one variable, and then iterate through to remove the columns.

If a for loop is the best way to go, how would I set it up?

  • 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-11T15:08:41+00:00Added an answer on June 11, 2026 at 3:08 pm

    You want to gather those dataframes into a list and then run the Extract function over them. The first argument given to “[” should be TRUE so that all rows are obtained, and the second argument should be the column names (I made up three dataframes that varied in their row numbers and column names but all had ‘Time’ and ‘Value’ columns:

    > datlist <- list(dat1,dat2,dat3)
    > TimVal <- lapply(datlist, "[", TRUE, c("Time","Value") )
    > TimVal
    [[1]]
      Time Value
    1 2:00     1
    2 2:05     4
    
    [[2]]
      Time Value
    1 2:00     1
    2 2:05     4
    
    [[3]]
        Time Value
    1   2:00     1
    2   2:05     4
    2.1 2:05     4
    1.1 2:00     1
    

    This is added in case the goal was to have them all together in the same dataframe:

    > do.call(rbind, TimVal)
        Time Value
    1   2:00     1
    2   2:05     4
    3   2:00     1
    4   2:05     4
    11  2:00     1
    21  2:05     4
    2.1 2:05     4
    1.1 2:00     1
    

    If you are very new to R you may not have figured out that the last code did not change TimVal; it only showed what value would be returned and to make the effect durable you would need to assign to a name. Perhaps even the same name:

    TimVal <- do.call(rbind, TimVal):
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
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 a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
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.