Im trying to read a csv file into R that has date values in some of the colum headdings.
As an example, the data file looks something like this:
...and my read.csv logic looks like this
The read.csv works fine except it modifies the name of the colums with dates as follows:
Is there a way to prevent this, or a easy way to correct afterwards?
Answer:
Set
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?
Answer:
Set
check.names=FALSE
. But be aware that 1/1/2001
et al are syntactically invalid names, therefore they may cause you some headaches.
No comments:
Post a Comment