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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:22:26+00:00 2026-06-07T01:22:26+00:00

Whenever I read in a file using read.csv() with option header=T , the headers

  • 0

Whenever I read in a file using read.csv() with option header=T, the headers change in weird (but predictable) ways. A header name which ought to read "P(A<B)" becomes "P.A.B.", for instance:

> # when header=F:
> myfile1 <- read.csv(fullpath,sep="\t",header=F,nrow=3)
> myfile1
     V1    V2     V3
1    ID  Name P(A>B)
2 AB001 Alice  0.997
3 AB002   Bob  0.497
>
> # When header=T:
> myfile2 <- read.csv(fullpath,sep="\t",header=T,nrow=3)
> myfile2
     ID    Name P.A.B.
1 AB001   Alice  0.997
2 AB002     Bob  0.497
3 AB003 Charles  0.732

I tried to fix it like this, but it didn’t work:

> names(myfile2) <- myfile1[1,]
> myfile2
      3       3     3
1 AB001   Alice 0.997
2 AB002     Bob 0.497
3 AB003 Charles 0.732

So then I tried to use sub() to write a function that would take any vector "arbitrary.lengths.here." and return a vector "arbitrary(lengths>here)", but I didn’t really get anywhere, and I started to suspect that I was making this problem more complicated than it had to be.

How would you deal with this problem of headers? Was I on the right track with sub()?

  • 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-07T01:22:27+00:00Added an answer on June 7, 2026 at 1:22 am

    Set check.names=FALSE in read.csv()

    read.csv(fullpath,sep="\t", header=FALSE, nrow=3, check.names=FALSE)
    

    From the help for ?read.csv:

    check.names

    logical. If TRUE then the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names. If necessary they are adjusted (by make.names) so that they are, and also to ensure that there are no duplicates.

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

Sidebar

Related Questions

I'm using opencsv in my application but whenever I try to read my csv
Whenever I want to read or write into a binary file using C, I
What kind of file formats can be read using PIG? How can I store
I'm trying to read a binary file (which represents a matrix in Matlab) in
I have written a program which takes a file as input and whenever it
I've read that whenever you're using a UITableView you should conform your controller class
I am building the Email where I am parsing the .csv file which consists
Is there any way, using C#, to monitor a specific file then change its
I am using the java properties file construct. At the beginning I read it
I'm trying to read data from a socket, however whenever I try to read

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.