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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:05:07+00:00 2026-05-26T03:05:07+00:00

Maybe this is a simple question, but I’m trying to change the position of

  • 0

Maybe this is a simple question, but I’m trying to change the position of columns in a data frame in R. I’ve got this data frame

TargetID   1065197   1005204     97610   1011789    101075   1002206
cg00000029 0.4192448 0.4177188 0.4797760 0.4214448 0.5500357 0.5535228
cg00000108 0.9191919 0.9358317 0.9428818 0.9397804 0.9293985 0.9495835
cg00000109 0.8935743 0.9157031 0.8731022 0.8734130 0.9226335 0.8980497
cg00000165 0.1387203 0.1699675 0.2031603 0.1683728 0.1822674 0.1623122
cg00000236 0.7502784 0.7324294 0.7895553 0.7096000 0.7878484 0.7747281
cg00000289 0.5698198 0.5864769 0.6527094 0.5058923 0.6033058 0.6524675

And I want to rearrange the positions using this tabulated text file, which indicates every pair of columns in order

101075 1005204
97610 1002206
1011789 1065197

So the result must be something like this

colnames(reordered_data_frame)
TargetID 101075 1005204 97610 1002206 1011789 1065197

Any ideas?

  • 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-26T03:05:08+00:00Added an answer on May 26, 2026 at 3:05 am

    If you have a vector of column names in order, say:

    colorder=c(101075, 1005204, 97610, 1002206,1011789 ,1065197)
    

    You can re-order your columns using (assuming your dataframe is named dat):

    newDf <- dat[, c("TargetID", colorder)]
    

    Normally, you’d need to call as.character() on colorder (since the column names are numbers), but when we concatenate the “TargetID” text, the vector c("TargetID", colorder) is converted to character. In general, though, it isn’t the best idea to use numerics as column names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This maybe a very noobish question but I am trying to implement a simple
Ok so this maybe a simple/silly question but I don't know so here goes:
This maybe a really simple question but for some reason my code isn't working.
Maybe this is a simple question, but I didn't find answer in web. I
I new to ASP.NET MVC so this question maybe simple for you but please
This is maybe a really simple question, but I couldn't locate an answer: For
This maybe a simple question, but how do i get all files in a
Maybe this is a too simple question but I'm kind of stuck here. I've
maybe this is a very simple question, but forgot the answer about it because
Maybe this is a simple question, but I can't figure it out how can

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.