# This works
dates(minor.test[1:2], format = "y-m-d")
[1] NA NA
Warning messages:
1: NAs introduced by coercion
2: NAs introduced by coercion
3: NAs introduced by coercion
# this fails
dates(minor.test[1:4], format = "y-m-d")
Error in if (any(i)) y[i] <- ifelse(y[i] < cut.off, y[i] + century[2], :
missing value where logical needed
In addition: Warning messages:
1: NAs introduced by coercion
2: NAs introduced by coercion
3: NAs introduced by coercion
# as does this
dates(minor.test, format = "y-m-d")
Error in if (any(i)) y[i] <- ifelse(y[i] < cut.off, y[i] + century[2], :
missing value where logical needed
In addition: Warning messages:
1: NAs introduced by coercion
2: NAs introduced by coercion
3: NAs introduced by coercion
# this works
dates(na.omit(minor.test), format = "y-m-d")
[1] 88-02-08 88-02-08 87-11-23 88-09-03 91-10-15 92-01-14 92-02-18
dates() correctly produces the first NA's but becomes confused when
strings with times start appearing. The below examples suggest the
POSIXct class in the base package also has some trouble.
as.POSIXct(minor.test[4])
[1] "1988-02-08 EET"
as.POSIXct(minor.test[1:10])
Error in fromchar(x) : character string is not in a standard unambiguous format
as.POSIXct(na.omit(minor.test[1:10]))
[1] "1988-02-08 EET" "1988-02-08 EET" "1987-11-23 EET" "1988-09-03 EEST"
[5] "1991-10-15 EET" "1992-01-14 EET" "1992-02-18 EET"
My problem is that the data are contained in a PostgreSQL database and
I am accessing them using the RPgSQL package. There are typically
several data variables in my data sets and in many cases the dates are
missing. Thus, using na.omit is possible but this problem seems to
preclude letting RPgSQL do the type conversion. I have temporarily
solved the problem by just returning the postgres date type as
character, this is a little unsatisfactory.
version
_
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status
major 1
minor 2.3
year 2001
month 04
day 26
language R
Any help would be appreciated.
Regards,
Markus
Markus Jantti | Department of Statistics
markus.jantti at abo.fi | Abo Akademi University
http://www.abo.fi/~mjantti | FIN 20500 Turku, Finland
358-9-643 747 (Home/Voice) | 358-2-2154 161 (Office/Voice)
| 358-2-2154 677 (Office/Fax)
PGP public key: http://www.abo.fi/~mjantti/pubring.asc
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear All:
I am having some trouble with date variables when NAs are present. The
following example illustrates (see below for output of version):
[...]
dates() correctly produces the first NA's but becomes confused when
strings with times start appearing. The below examples suggest the
POSIXct class in the base package also has some trouble.
The trouble is your end: the error message means what it says,
and is explained the help page. As the help page says,
specify the precise format, by in your case
as.POSIXct(strptime(minor.test[1:10], "%Y-%m-%d"))
[1] "NA" "NA" "1988-02-08 GMT" "1988-02-08 GMT"
[5] "NA" "1987-11-23 GMT" "1988-09-03 BST" "1991-10-15 BST"
[9] "1992-01-14 GMT" "1992-02-18 GMT"
Unless you specify the format, there is no way to distinguish invalid
entries from strings you mean to be NA, so the guessing algorithm give
up.
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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._