page took 0.31 seconds • home | my page | my email . email
Mail Addresses Calendar Notepad [EMAIL PROTECTED] sign out << Hide Folders Check Messages Compose Message POP Accounts | Mail Preferences | Help Folders Inbox Drafts Sent Trash (Empty) Bulk Mail (Empty) My Folders edit R Rcom Rtmp Saved this Tx zoo Spam Tools info Spam Filter Level: OffLowMediumMedium-highHigh My Block List Image Filter Custom Filters Now Live: 125MB Free Storage Upgrade Send/Receive 10MB emails! < Prev Next > Back to Inbox Print View Full Header As AttachmentAs Inline Text Move to Folder----- Folders ------InboxDraftsSentTrashBulk Mail---- My Folders ----RRcomRtmpSavedthisTxzoo Message is not flagged. [ Flag for Follow Up ] If instead of a data frame of POSIXlt objects you use a matrix of POSIXct objects then that should work. That is, replace tmp <- data.frame(t.start.cdt, t.end.cdt) with tmp <- cbind(t.start.cdt+0, t.end.cdt+0) in your code. Date: Tue, 5 Oct 2004 14:56:41 -0700 From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Subject: Re: [R] correct my method of estimating mean of two POSIXlt data frames My apology for not properly quoting someone. Let me amend my original email. In R version 1.8.1, if I have two objects that look like: > t.start.cdt[1:4] [1] "2003-07-09 11:02:25" "2003-07-09 11:10:25" "2003-07-09 11:30:25" [4] "2003-07-09 12:00:25" > class(t.start.cdt) [1] "POSIXt" "POSIXlt" > t.end.cdt[1:4] [1] "2003-07-09 11:02:35" "2003-07-09 11:10:35" "2003-07-09 11:30:35" [4] "2003-07-09 12:00:35" > class(t.end.cdt) [1] "POSIXt" "POSIXlt" I could estimate the mean of "pairs" of times (such as t.start.cdt[1] and t.end.cdt[1]) using these commands: tmp <- data.frame(t.start.cdt, t.end.cdt) tmp <- apply(tmp, MARGIN=1, FUN=mean) class(tmp) <- c("POSIXt", "POSIXct") t.mean.cdt <- as.POSIXlt(tmp) In version 1.9.1, I get these warnings Warning messages: 1: longer object length is not a multiple of shorter object length in: cl == c("Date", "POSIXct", "POSIXlt") 2: longer object length is not a multiple of shorter object length in: cl == c("Date", "POSIXct", "POSIXlt") 3: argument is not numeric or logical: returning NA in: mean.default(newX[, i], ...) 4: argument is not numeric or logical: returning NA in: mean.default(newX[, i], ...) I think I wrote a rather convoluted way around this problem, which I stated in my original email, but I don't "understand" why the method stated here doesn't work. Can you explain what I'm missing. Also, please note that in my original message, I used underscore instead of period in the variable names. Mike Berkeley, California, USA On Tue, 5 Oct 2004 21:13:05 +0100 (BST), Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > On Tue, 5 Oct 2004 "[EMAIL PROTECTED]" (but with no name nor signature) > wrote: > > Quoting someone without credit (and therefore in breach of their > copyright) > > > > > > If a.lt and b.lt are the two vectors of POSIXlt dates then try > > > converting each to POSIXct and unclassing to make each numeric. > > > Take the mean of the two numeric vectors and convert them back to > > > > I see. I'm a little confused with the use of class/unclass versus > > as.XX. For example, instead of using unclass, why wouldn't I use > > as.numeric? Could someone explain the difference? > > That advice is wrong: you should not be unclassing before forming the > mean as mean() has a method for POSIXct. ______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html