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@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@iupui.edu
Imaging Sciences, Department of Radiology, IU School of Medicine
-
<p><br><hr size=1><b><a href=http://uk.yahoo.com/mail/tagline_vip/?http://fifaworldcup.yahoo.com/fc/en/spl>Relive the FIFA World Cup goals with exclusive video highlights!</a></b><br><br>
<a href=http://uk.yahoo.com/mail/tagline_fifa/?http://fifaworldcup.yahoo.com/fc/en>http://fifaworldcup.yahoo.com/fc/en</a>