[R] importing date vector with read.table
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Dec 10 10:20:57 CET 2010
On Fri, 10 Dec 2010, Jack Johnson wrote:
> Hi,
>
> I understand this should be an easy task but I am still struggling a bit to
> read a .txt file with a date vector. My code is as below:
>
>
> data<-read.table(file.choose(),header=TRUE,sep="\t",dec=",",colClasses=c("Date","numeric","numeric","numeric"))
>
> But I am getting an error:
>
> Error in charToDate(x) :
> character string is not in a standard unambiguous format
>
>
> because my date vector is in a format below:
>
> format="%d.%m.%Y"
>
>
> But how can i define the date format for date vector in read.table
> function....?
It is easiest to simply read the column as character, and convert
later by as.Date(x, format="%d.%m.%Y")
You might want to consider using read.delim2 to get all the usual
defaults for a tab-delimited file in a locale using comma as decimal
separator.
>
> Br,
> Jack
>
> [[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.
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list