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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:04:29+00:00 2026-06-18T02:04:29+00:00

I am saving my column names of a data.frame into a variable in R

  • 0

I am saving my column names of a data.frame into a variable in R. Some of my columns names contain a plus sign +. R changes the + into a . when saving it into a variable. I would like to retain the + so that i can pick these columns again automatically when I need them.

Here is the command I am using to save the column names into a variable:

for (u in 1:50) {
    k <- colnames[u]
    f <- append(f,k)
}
## f is defined previously in my program

Here is the command I am using to get the names I need again:

file2 <- file1[,f]

Example: column1+ is named column1. in the variable f

Note: This happened to the brackets () as well as slashes /

Any Ideas how I can get around this problem?

  • 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-18T02:04:30+00:00Added an answer on June 18, 2026 at 2:04 am

    Just so the question remains answered. Set the option check.names to FALSE while reading the data.frame using read.table as:

    read.table(file, check.names = FALSE)
    

    Note: As @Roland says under the comments, it is better to keep the column names clean rather than using this parameter. You may also run into situations where certain functions automatically convert the names back. For example,

    df <- data.frame('x+y' = 1:4, 'a+b' = 5:8, check.names = FALSE)
    > df
    #   x+y a+b
    # 1   1   5
    # 2   2   6
    # 3   3   7
    # 4   4   8
    
    # Now adding a 3rd column, using `transform`
    transform(df, c=9:12)
    #   x.y a.b  c  # note that it reverts back
    # 1   1   5  9
    # 2   2   6 10
    # 3   3   7 11
    # 4   4   8 12
    
    transform(df, c=9:12, check.names = FALSE)
    #   x+y a+b
    # 1   1   5
    # 2   2   6
    # 3   3   7
    # 4   4   8
    

    You’ll have to know ALL functions that has check.names=FALSE and remember to use them correctly. This is at least one problem I could think of. Its rather better to have the columns without conflict.

    Including operators such as + in column names can also interfer with the formula model interface:

    dat <- data.frame('a+x'=c(1,2,3,4),b=c(2,4,6,8),check.names=FALSE)
    lm(dat$b~dat$a+x)
    Error in eval(expr, envir, enclos) : object 'x' not found
    

    You would need to use lm(dat$b~dat[,'a+x']).

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

Sidebar

Related Questions

Is there any way to change(increase) the data type of a column while saving
I'm saving data to a table, but I also need a column with a
between saving a key name like this for(var key in this.data) { var key_name
I need to save some data to an existing table. So i have column
I want to save some data into sqlite database and the read it, there
I'm using a UserType to maintain a column (Created) in my db. When saving
After saving a String value into memcached using the Danga client, I attempted to
When saving a new entity something strange happens... I have a data grid with
I'm saving a struct into a .dat file. Lets suppose I have to edit
My app is saving some images on the SD Card, in the AppImages directory

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.