Skip to content

NAs in chron objects

2 messages · Markus Jäntti, Brian Ripley

#
Dear All:

I am having some trouble with date variables when NAs are present. The
following example illustrates (see below for output of version):
+                 "1988-02-08", "NA", "1987-11-23", "1988-09-03", "1991-10-15",
+                 "1992-01-14", "1992-02-18")
[1] "NA"         "NA"         "1988-02-08" "1988-02-08" "NA"        
 [6] "1987-11-23" "1988-09-03" "1991-10-15" "1992-01-14" "1992-02-18"
[1] NA NA
Warning messages: 
1: NAs introduced by coercion 
2: NAs introduced by coercion 
3: NAs introduced by coercion
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
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
[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.
[1] "1988-02-08 EET"
Error in fromchar(x) : character string is not in a standard unambiguous format
[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.
_                
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
#
On Fri, 18 May 2001, Markus Jantti wrote:

            
[...]
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.