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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:21:07+00:00 2026-06-16T10:21:07+00:00

I have a table in csv format, the data is the following: 1 3

  • 0

I have a table in csv format, the data is the following:

            1           3            1          2
1415_at 1   8.512147859 8.196725061 8.174426394 8.62388149
1411_at 2   9.119200527 9.190318548 9.149239039 9.211401637
1412_at 3   10.03383593 9.575728316 10.06998673 9.735217522
1413_at 4   5.925999419 5.692092375 5.689299161 7.807354922

When I read it with:

m <- read.csv("table.csv")

and print the values of m, I notice that they change to:

        X   X.1        X1       X3      X1.1       X4
1 1415_at   1       8.512148 8.196725  8.174426 8.623881

I made some manipulation to keep only those columns that are labelled 1 or 2, so I do that with:

smallerdat <- m[ grep("^X$|^X.1$|^X1$|^X2$|1\\.|2\\." , names(m) ) ]

write.csv(smallerdat,"table2.csv")

it writes me the file with those annoying headers and that first column added, which I do not need it:

      X   X.1        X1             X1.1       X2
1 1415_at   1       8.512148   8.174426 8.623881

so when I open that data in Excel the headers are still X, X.1 and son on. What I need is that the headers remain the same as:

                     1      1           2
1415_at 1       8.196725061 8.174426394 8.62388149

any help?

Please notice also that first column that is added automatically, I do not need it, so how I can get rid that of that column?

  • 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-16T10:21:08+00:00Added an answer on June 16, 2026 at 10:21 am

    There are two issues here.

    1. For reading your CSV file, use:

      m <- read.csv("table.csv", check.names = FALSE)
      

      Notice that by doing this, though, you can’t use the column names as easily. You have to quote them with backticks instead, and will most likely still run into problems because of duplicated column names:

      m$1
      # Error: unexpected numeric constant in "mydf$1"
      mydf$`1`
      # [1]  8.512148  9.119201 10.033836  5.925999
      
    2. For writing your “m” object to a CSV file, use:

      write.csv(m, "table2.csv", row.names = FALSE)
      

    After reading your file in using the method in step 1, you can subset as follows. If you wanted the first column and any columns named “3” or “4”, you can use:

    m[names(m) %in% c("", "3", "4")]
    #                    3        4
    # 1 1415_at 1 8.196725 8.623881
    # 2 1411_at 2 9.190319 9.211402
    # 3 1412_at 3 9.575728 9.735218
    # 4 1413_at 4 5.692092 7.807355
    

    Update: Fixing the names before using write.csv

    If you don’t want to start from step 1 for whatever reason, you can still fix your problem. While you’ve succeeded in taking a subset with your grep statement, that doesn’t change the column names (not sure why you would expect that it should). You have to do this by using gsub or one of the other regex solutions.

    Here are the names of the columns with the way you have read in your CSV:

    names(m)
    # [1] "X"    "X.1"  "X1"   "X3"   "X1.1" "X2"  
    

    You want to:

    • Remove all “X”s
    • Remove all “.some-number”

    So, here’s a workaround:

    # Change the names in your original dataset
    names(m) <- gsub("^X|\\.[0-9]$", "", names(m))
    # Create a temporary object to match desired names
    getme <- names(m) %in% c("", "1", "2")
    # Subset your data
    smallerdat <- m[getme]
    # Reassign names to your subset
    names(smallerdat) <- names(m)[getme]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table in csv format in Excel: 1 1 1 2
I have the following gene information in a csv format table: 1 1 1
I have a CSV file in the following format: id,code,date,address,complete_url Example data from the
On a new project I work on I have data in CSV format to
I have the following distance matrix in csv format. http://palaeomath.palass.org/images/mds/T1.jpg Using PHP, how could
I have a data file in CSV format that has the some data like
I have the following code that exports a csv file : //Selecting Item Data
Currently have : LOAD DATA LOCAL INFILE '/Users/RkG/Desktop/Microblogs.csv' INTO TABLE blogs This is an
I have a table of golf match-ups taken from Betfair's downloadable CSV files of
I have table of data that is sorted as follows: Item | Sample |

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.