Nick Sherrard
2002-Jun-27 15:30 UTC
[R] lattice and dates (correcting e-mail formatting glitch - sorry!!)
Hi I'm fairly new to R and the list, so please take what I say accordingly! Far as I can see, strptime gives you a string in some specified format. In order to do any kind of numerically-based modelling with that, you need to obtain a number to work with. One way to do this is by getting the time with Sys.time() instead and coercing it to a number using as.integer(): > as.integer(Sys.time()) I dare say you could also set up a structure in which there are both numeric and string fields, do your modelling with the former and labelling with the latter:> now=Sys.time() > numero= as.integer(now) > dateo= format(now, "%a, %b %d, %Y") > timeo= format (now, "%X") > item=list(numeric=numero, strings=c(timeo,dateo))This seems to do the trick, and gives you a list with values that look like this.> item$numeric [1] 1025176725 $strings [1] "12:18:45" "Thu, Jun 27, 2002" I guess many of us might also choose to normalize the $numeric by subtracting some suitable base date/time from each reading of numero, which appears to be the number of seconds since 1/1/70, to give a more useful time origin! Nick Sherrard, PhD reduplicativeblending at yahoo.co.uk ______________________________________________________ Subject: [R] lattice and dates I've got some data that is recorded at various times during the day. I create a time stamp is created from date and time strings like this: > timestamp <- strptime( paste( datestring, timestring), "%D %X" ) Then I'd like to use lattice to plot the time dependence by doing something like > xyplot( value ~ timestamp | subject ) This fails with Error in as.double.default(x) : (list) object cannot be coerced to vector type 14 In addition: Warning message: Both x and y should be numeric in: xyplot( value ~ timestamp | subject ) I was sure I saw something like this on r-help recently, but I can't seem to track it down now. Can anyone help me out? Thanks, Mike - -- Michael A. Miller mmiller3 at iupui.edu Imaging Sciences, Department of Radiology, IU School of Medicine - __________________________________________________ Everything you'll ever need on one web page from News and Sport to Email and Music Charts -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Michael A. Miller
2002-Jun-27 18:46 UTC
[R] lattice and dates (correcting e-mail formatting glitch - sorry!!)
Hi Nick,
Thanks for the suggestions. At the suggestion of another reader,
I've settled on using the chron package (from CRAN). I'll append
an example for those who are interested.
Mike
--
Michael A. Miller mmiller3 at iupui.edu
Imaging Sciences, Department of Radiology, IU School of Medicine
df.data <- read.table('df.log')
names(df.data) <- c( 'datestamp', 'timestamp', 'dev',
'size',
'used', 'available', 'percentage',
'path')
library(chron)
library(lattice)
print( df.data$datestamp )
print( df.data$timestamp )
df.data$date <- chron( dates=as.vector(df.data$datestamp),
times=times(df.data$timestamp) )
#df.data$date <- strptime( paste( df.data$datestamp, df.data$timestamp),
"%D %X" )
print( df.data$date )
pos <- pretty( as.numeric( df.data$date ) )
lab <- as.character( dates(df.data$date) )
xyplot( used/size ~ as.numeric(date) | path, data=df.data,
scales = list(x = list(at = pos, labels = lab )))
sample df.log:
06/25/02 13:48:58 node2:/data2 67638296 48221224 15981176 76% /data2
06/26/02 15:59:23 node2:/data2 67638296 52972176 11230224 83% /data2
06/27/02 12:07:45 node2:/data2 67638296 56713248 7489152 89% /data2
06/25/02 13:48:58 node3:/data3 67638296 50150280 14052120 79% /data3
06/26/02 15:59:23 node3:/data3 67638296 54900656 9301736 86% /data3
06/27/02 12:07:45 node3:/data3 67638296 56775680 7426720 89% /data3
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._