Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read.csv appends/modifies column headings with date values

Tags:

dataframe

r

csv

I'm trying to read a csv file into R that has date values in some of the colum headings.

As an example, the data file looks something like this:

ID  Type   1/1/2001  2/1/2001  3/1/2001  4/1/2011
A   Supply       25        35        45        55  
B   Demand       26        35        41        22
C   Supply       25        35        44        85  
D   Supply       24        39        45        75  
D   Demand       26        35        41        22

...and my read.csv logic looks like this

dat10 <- read.csv("c:\data.csv",header=TRUE, sep=",",as.is=TRUE)

The read.csv works fine except it modifies the name of the colums with dates as follows:

x1.1.2001  x2.1.2001  x3.1.2001  x4.1.2001

Is there a way to prevent this, or a easy way to correct afterwards?

like image 464
MikeTP Avatar asked Dec 13 '22 03:12

MikeTP


1 Answers

Set check.names=FALSE. But be aware that 1/1/2001 et al are syntactically invalid names, therefore they may cause you some headaches.

like image 152
Joshua Ulrich Avatar answered Jan 08 '23 18:01

Joshua Ulrich