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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:22:28+00:00 2026-05-27T06:22:28+00:00

In my code, I am filling the columns of a dataframe with vectors, as

  • 0

In my code, I am filling the columns of a dataframe with vectors, as so:

df1[columnNum] <- barWidth

This works fine, except for one thing: I want the name of the vector variable (barWidth above) to be retained as the column header, one column at a time. Furthermore, I do not wish to use cbind. This slows the execution of my code down considerably. Consequently, I am using a pre-allocated dataframe.

Can this be done in the vector-to-column assignment? If not, then how do I change it after the fact? I can’t find the right syntax to do this with colNames().

TIA

  • 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-27T06:22:29+00:00Added an answer on May 27, 2026 at 6:22 am

    If you have the list of names of vectors you want to apply you could do:

    namevec <- c(...,"barWidth"...,)
    columnNums <- c(...,10,...)
    
    df1[columnNums[i]] <- get(namevec[i])
    names(df1)[columnNums[i]] <- namevec[i]
    

    or even

    columnNums <- c(barWidth=4,...)
    for (i in seq_along(columnNums)) {
       df1[columnNums[i]] <- get(names(columnNums)[i])
    }
    names(df1)[columnNums] <- names(columnNums)
    

    but the deeper question would be where this set of vectors is coming from in the first place: could you have them in a list all along?

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

Sidebar

Related Questions

Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
So I have this piece of code, and let's assume I'm filling out a
I've a ListView with two columns and i'm filling the ListView using the code
I have this code: marginsBetween = 20 background = '#000000' columns = 6 rows
Currently our code uses a for-loop for filling a buffer holding a Unicode string
I am looking over this piece of code, and am having trouble with the
I can't understand why does vector empty after it's filling. The code is: bool
The following code does not yield any invalid values even though I am filling
I'm filling a ComboBox with DataGridView cells' values. Now, I don't want to repeat
I have this really random problem with is bugging me. It works at the

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.