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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:54:49+00:00 2026-06-12T17:54:49+00:00

Trying to create a data.frame like this: a = foo bar = data.frame(a =

  • 0

Trying to create a data.frame like this:

a = "foo"
bar = data.frame(a = 1:3)

But the name of the column is a, not foo:

> bar
  a
1 1
2 2
3 3

The column can be renamed after creating data.frame, but how to easily assign it’s name by a variable just in the same data.frame command?

  • 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-12T17:54:50+00:00Added an answer on June 12, 2026 at 5:54 pm

    The setNames() function should work for you:

    a <- "Numbers"
    b <- "Letters"
    
    bar <- setNames(data.frame(1:3, letters[1:3]), c(a, b))
    bar
    #   Numbers Letters
    # 1       1       a
    # 2       2       b
    # 3       3       c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Pass a data.frame column name to a function I am trying to
I have a data.frame and I'm trying to create a frequency table that shows
I am trying to use the structure() function to create a data frame in
I'm trying to create separate data.frame objects based on levels of a factor. So
I have a data frame like this: Server Date Server Space 1 2010-01-30 server1
One column of my data frame has words and phrases. I am trying to
I'm trying to learn R's XML package. I'm trying to create a data.frame from
I'm trying to create an as.data.frame.by method which basically melts the N-dimensional by object
I am trying to create a structure diagram from the data like the following:
I am trying create a data.frame from which to create a graph. I have

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.