[R] Read.table mucks up headers

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Mon Apr 14 17:50:08 CEST 2014

You have not posted the input to your code so it is not reproducible. Also, you have posted in HTML, which is notorious for corrupting R code and data in emails.

If I were to guess, though, it looks to me like you are working with a UTF-8 file with a Byte Order Mark (header). I don't know the "correct" way to address this, but if you only have plain text data then the rest of your table should be valid and you could reset the name of the first column yourself like

names(sim)[1] <- "X"
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
Sent from my phone. Please excuse my brevity.

On April 14, 2014 7:52:11 AM PDT, Pavneet Arora <pavneet.arora at uk.rsagroup.com> wrote:
>Hey All
>I am trying to read in a small text file using read.table. 
>structure(list(��...X. = 1:7, Y1 = c(2.5501, 4.105, 5.4687, 7.0009, 
>8.5066, 9.785, 11.5167), Y2 = c(2.5501, 4.105, 5.4687, 11.0009, 
>8.5066, 9.785, 11.5167), Y3 = c(2.5501, 4.105, 5.4687, 7.0009, 
>8.5066, 9.785, 15.5167)), .Names = c("��...X.", "Y1", "Y2", "Y3"
>), class = "data.frame", row.names = c(NA, -7L))
>But for some reason my first header comes as "?...X. ", instead of just
>"X". Can some one please tell me why? And how to fix it?
>This is what I did in my code, using R-studio
>> sim<-read.table("C:/00Pavneet/# MSc/# temp/sim data 1.txt",header=T)
>> View(sim)
>MORE TH>N is a trading style of Royal & Sun Alliance Insurance plc (No.
>93792). Registered in England and Wales at St. Mark���s Court, Chart
>Way, Horsham, West Sussex, RH12 1XL. 
>Authorised by the Prudential Regulation Authority and regulated by the
>Financial Conduct Authority and the Prudential Regulation Authority.
>	[[alternative HTML version deleted]]
>R-help at r-project.org mailing list
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list