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

  • Home
  • SEARCH
  • 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 6777875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:12:00+00:00 2026-05-26T16:12:00+00:00

I want make changes in big data.frame column names (names(mp)) with the help of

  • 0

I want make changes in big data.frame column names (names(mp)) with the help of changing a single column from other data.frame (mp$name)

#first data frame : column chooser, small data.frame with 
# list of columns and other information  

 mp <- data.frame(name = c("A", "C", "D"), pos = 1:3) # number of rows 
                                                     #in real dataset is> 5,000 
              name pos
            1    A   1
            2    C   2
            3    D   3

Big dataframe, > 10,000 variables in read sense but just four is shown here

    # second data.frame  
 mydf <- data.frame(Aa= 1:10, Ab = 11:20, Ba = 21:30, Bb = 31:40, 
Ca = 41:50, Cb = 51:60, Da = 61:60,Db = 61:70)

Each values in mp$name corresponds to two variable – for example A corresponds to Aa, Ab similarly B correspond to Ba and Bb. Every such duplicated variables have suffix “a” and “b”

> mydf
   Aa Ab Ba Bb Ca Cb Da Db
1   1 11 21 31 41 51 61 61
2   2 12 22 32 42 52 60 62
3   3 13 23 33 43 53 61 63
4   4 14 24 34 44 54 60 64
5   5 15 25 35 45 55 61 65
6   6 16 26 36 46 56 60 66
7   7 17 27 37 47 57 61 67
8   8 18 28 38 48 58 60 68
9   9 19 29 39 49 59 61 69
10 10 20 30 40 50 60 60 70

My idea is if something is removed from mp$name should remove the corresponding column in the dataframe mydf. For example in above example there is no “B”, thus the columns Ba and Bb should be removed from the mydf to make new dataframe mydf1

        mydf1
       Aa Ab Ca Cb Da Db
    1   1 11 41 51 61 61
    2   2 12 42 52 60 62
    3   3 13 43 53 61 63
    4   4 14 44 54 60 64
    5   5 15 45 55 61 65
    6   6 16 46 56 60 66
    7   7 17 47 57 61 67
    8   8 18 48 58 60 68
    9   9 19 49 59 61 69
    10 10 20 50 60 60 70

Although there is deletion of single var from mp (corresponding two variables from mydf is shown here) is removed, there are can be n number of such deletion and the final should maintain the order of column names or mp elements

Help is appreciated

  • 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-26T16:12:00+00:00Added an answer on May 26, 2026 at 4:12 pm

    Extract the name and their lengths. Knowing the lengths makes it easier to chop off the last letter (the a/b suffix); I’m not assuming that all the names are just 2 characters.

    nm <- names(mydf)
    lens <- nchar(nm)
    

    Subset based on column names without the last letter.

    mydf1 <- mydf[substr(nm, 1, lens-1) %in% mp$name]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make some changes to the stock Mms Android application and install
Specifically, I want to create a backup of a list, then make some changes
I have style sheet with a class name changebackgroundcolor i want make change in
I am processing a big .gz file using PHP (transfering data from gz to
I want to make a fourier-transformation of an image. But how can I change
I want to change Control(@Control) directive in a way to make it redistributable and
I want make datetimepicker in my project. Using jquery how it is possible? I
Let's say I want make some of my sources publicly available via my blog
I am traversing a HTML document using javascript DOM. I want make a list
I want to make an etag that matches what Apache produces. How does apache

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.