Hello everybody out there using R, How can I import data with a numeric header from a .csv-file? My file example.csv has the following content (a duplicate measurement of potentials for three different currents): 1; 2; 6 1.0; 2.1; 5.9 1.1; 2.0; 6.0 I try to import the data by using:>measurement <- read.table("example.csv",sep=";",header=T)However, the values in the header are renamed to the column names X1, X2 and X3. When I try to plot the data, I don't get the right x-values (the three different currents 1, 2 and 6), but 1.0, 2.0 and 3.0:>plot(mean(measurement))Thanks in advance.
Henrique Dallazuanna
2009-Sep-25 12:46 UTC
[R] Data import from .csv-file with numeric header
Try this:
measurement <- read.table("example.csv", sep = ";",
header = TRUE, check.names = FALSE)
plot(mean(measurement), names(measurement), xaxt = 'n')
axis(1, names(measurement))
On Fri, Sep 25, 2009 at 3:53 AM, Tobias Ruff <lisemint at ymail.com>
wrote:> Hello everybody out there using R,
>
> How can I import data with a numeric header from a .csv-file?
> My file example.csv has the following content (a duplicate measurement of
potentials for three different currents):
> 1; 2; 6
> 1.0; 2.1; 5.9
> 1.1; 2.0; 6.0
>
> I try to import the data by using:
>>measurement <-
read.table("example.csv",sep=";",header=T)
> However, the values in the header are renamed to the column names X1, X2
and X3.
> When I try to plot the data, I don't get the right x-values (the three
different currents 1, 2 and 6), but 1.0, 2.0 and 3.0:
>>plot(mean(measurement))
>
> Thanks in advance.
>
>
>
>
> ______________________________________________
> 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.
>
--
Henrique Dallazuanna
Curitiba-Paran?-Brasil
25? 25' 40" S 49? 16' 22" O
Tobias Ruff wrote:> Hello everybody out there using R, > > How can I import data with a numeric header from a .csv-file? > My file example.csv has the following content (a duplicate measurement of potentials for three different currents): > 1; 2; 6 > 1.0; 2.1; 5.9 > 1.1; 2.0; 6.0 > > I try to import the data by using: > >> measurement <- read.table("example.csv",sep=";",header=T) >> > However, the values in the header are renamed to the column names X1, X2 and X3. > When I try to plot the data, I don't get the right x-values (the three different currents 1, 2 and 6), but 1.0, 2.0 and 3.0: > >> plot(mean(measurement))I got X1, X2 and X6, because 1, 2, and 6 aren't legal variable names. If you want to use them as names anyway, use the check.names=FALSE argument. I don't know how you tried to plot them so I can't help you with that. Duncan Murdoch