Hello, I am trying to read in a csv file with column such as "\\LS01\Processor(_Total)\% Processor Time" with the command read.csv("file"). However, the column name in the resulted data frame is changed to "X..LS01.Processor._Total....Processor.Time". Strangely, when I experimented with just reading the csv with the "head" flag set to false, the text was read correctly as the same to the raw file. I am wondering if anyone has encountered a similar problem. If so, I would really appreciate if you can share your insight. Best Regards, Derek [[alternative HTML version deleted]]
On Sat, 26 Sep 2009 01:58:38 -0400 Derek Foo <kc.derek at gmail.com> wrote: DF> I am trying to read in a csv file with column such as DF> "\\LS01\Processor(_Total)\% Processor Time" with the command DF> read.csv("file"). However, the column name in the resulted data DF> frame is changed to "X..LS01.Processor._Total....Processor.Time". Yous should maybe specify a unique separator for the columns which is not existant in your colum name strings. Otherwise things might get messed up. It is not clear what the separator is in your example since you did not show the numbers. Probably it is "\" so you have to specify it as such. ?read.csv Stefan
Gabor Grothendieck
2009-Sep-26 09:31 UTC
[R] data frame's column names not the same as in CSV
See the check.names argument in the help file for read.table. On Sat, Sep 26, 2009 at 1:58 AM, Derek Foo <kc.derek at gmail.com> wrote:> Hello, > > I am trying to read in a csv file with column such as > "\\LS01\Processor(_Total)\% Processor Time" with the command > read.csv("file"). However, the column name in the resulted data frame is > changed to "X..LS01.Processor._Total....Processor.Time". > > Strangely, when I experimented with just reading the csv with the "head" > flag set to false, the text was read correctly as the same to the raw file. > I am wondering if anyone has encountered a similar problem. If so, I would > really appreciate if you can share your insight. > > > Best Regards, > Derek > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
At 1:58 AM -0400 9/26/09, Derek Foo wrote:>Hello, > >I am trying to read in a csv file with column such as >"\\LS01\Processor(_Total)\% Processor Time" with the command >read.csv("file"). However, the column name in the resulted data frame is >changed to "X..LS01.Processor._Total....Processor.Time". > >Strangely,Not so strange. Data can be anything, but column names are names of variables. In R, as in most (all? many?) computer languages, variable names have rules they must follow. Yours don't follow R's rules. See Gabor's response to learn how to tell R to ignore the rules (in this particular instance). You will find, however, that later on, when you want to use those variables, it will be more difficult to use variables whose names do not follow the rules.> when I experimented with just reading the csv with the "head" >flag set to false, the text was read correctly as the same to the raw file. >I am wondering if anyone has encountered a similar problem. If so, I would >really appreciate if you can share your insight. > > >Best Regards, >Derek > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list >https://*stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062
Thank you all. I would like to say that it was my first time posting on the r-help mailing list. I am very impressed and grateful that I got the answer to my problem so quickly. Back to the issue, using read.csv (instead of read.csv) and turning off the check.names flag solved my problem. Derek On Sat, Sep 26, 2009 at 5:17 PM, Don MacQueen <macq@llnl.gov> wrote:> At 1:58 AM -0400 9/26/09, Derek Foo wrote: > >> Hello, >> >> I am trying to read in a csv file with column such as >> "\\LS01\Processor(_Total)\% Processor Time" with the command >> read.csv("file"). However, the column name in the resulted data frame is >> changed to "X..LS01.Processor._Total....Processor.Time". >> >> Strangely, >> > > Not so strange. Data can be anything, but column names are names of > variables. In R, as in most (all? many?) computer languages, variable names > have rules they must follow. Yours don't follow R's rules. > > See Gabor's response to learn how to tell R to ignore the rules (in this > particular instance). You will find, however, that later on, when you want > to use those variables, it will be more difficult to use variables whose > names do not follow the rules. > > > when I experimented with just reading the csv with the "head" >> flag set to false, the text was read correctly as the same to the raw >> file. >> I am wondering if anyone has encountered a similar problem. If so, I would >> really appreciate if you can share your insight. >> >> >> Best Regards, >> Derek >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://*stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http:// >> *www.*R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > -- > -------------------------------------- > Don MacQueen > Environmental Protection Department > Lawrence Livermore National Laboratory > Livermore, CA, USA > 925-423-1062 > -------------------------------------- >[[alternative HTML version deleted]]