[R] Problems merging with POSIXct objects and all = TRUE

Martin Maechler maechler at stat.math.ethz.ch
Tue Oct 16 18:20:01 CEST 2001


>>>>> "MM" == Martin Maechler <maechler at stat.math.ethz.ch> writes:

>>>>> "David" == "David Kane <David Kane" <a296180 at mica.fmr.com> writes:
    David> I am having problems using merge with all = TRUE when one of the
    David> dataframes has objects of class POSIXct. If this is a bug, let
    David> me know and I will report it to r-bugs. Here is an example:

    MM> ... (R version 1.3.0)

(example slightly compacted)

    >> x <- data.frame(a = as.POSIXct(Sys.time()+ (1:3)*10000), b=LETTERS[1:3])
    >> y <- data.frame(b = LETTERS[3:4], c = 1:2)
    >> merge(x, y)
    MM> b                   a c
    MM> 1 C 2001-10-04 23:11:06 1		# This answer is correct

    >> merge(x, y, all = TRUE)
    MM> Error in as.POSIXct.default(value) : Don't know how to convert `value' to class "POSIXct"

    MM> -------------

    MM> The reason is that merge(x,y, all = TRUE) fills in NAs at "appropriate"
    MM> places, and currently, it seems we have no (automatic) NA concept for
    MM> POSIX[cl]t objects:

    >> as.POSIXlt(NA)
    MM> Error in as.POSIXlt(NA) : Don't know how to convert `NA' to class "POSIXlt"
    >> as.POSIXct(NA)
    MM> Error in as.POSIXct.default(NA) : Don't know how to convert `NA' to class "POSIXct"
    >> as.POSIXct("NA")
    MM> Error in fromchar(x) : character string is not in a standard unambiguous format

    MM> This might be considered a bug although only in a loose sense of
    MM> the word.

I have now fixed this for "R-devel" (aka "1.4.0 to be").
as.POSIXct(*) and as.POSIXlt() now work with character "NA"s, and factors
are coerced to character  which fixes your   merge(x,y, all = TRUE) example
above.  Note that as.POSIXct(NA) still gives an error, duly IMO.

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list