Subject: RE: [R] Time plot question.

Heywood, Giles Giles.Heywood at CommerzbankIB.com
Thu Nov 13 10:10:34 CET 2003


The following is an example of a dataframe containing times, 
plus some numeric data.

foo <- c("12:39:26","12:40:22","12:41:19")
bar <- data.frame(foo,1:3,11:13)

Note that the times are of class 'factor' (their class changes
in this case, as they go into the dataframe).

To convert this dataframe to an 'its', do the following:

library(its)
its.format("%H:%M:%S")
its(x=as.matrix(bar[,2:3]),dates=as.POSIXct(x=strptime(as.character(bar[[1]]
),format=its.format())))

Incidentally, since these types of question come up from
time to time on the R-help ist, I intend to expand the 'its' 
documentation with some more examples and illustrations, in
a 'vignette'.

- Giles

> -----Original Message-----
> From: heimdal at aracnet.com [mailto:heimdal at aracnet.com]
> Sent: 12 November 2003 18:09
> To: ggrothendieck at myway.com
> Cc: r-help at stat.math.ethz.ch
> Subject: Subject: RE: [R] Time plot question.
> 
> 
> Hello,
> 
> Thank you for your reply. I am missing an intermediate step as
> 
> > plot( strptime( Time, format = "%H:%M:%S"), FreeMemory)
> Error in strptime(Time, format = "%H:%M:%S") :
>         invalid `x' argument
> > plot( strptime( c(Time), format = "%H:%M:%S"), FreeMemory)
> Error in strptime(c(Time), format = "%H:%M:%S") :
>         invalid `x' argument
> 
> does not work. My "Time" data is part of a data.frame. Do I need to
> "as.POSIXlt" this in some way, and if so, how?
> I will continue to work on this, and buy a suitable book on R 
> so as not to
> plague this excellent news group with such questions. I could 
> generate a
> sequence of ISODates similar to my
> data, but I would like to use the actual Time coordinates 
> instead. Here is
> my "Time" data below:
> 
> > Time
>   [1] 12:39:26 12:40:22 12:41:19 12:42:15 12:43:11 12:44:08 12:45:04
> 12:46:00
>   [9] 12:46:57 12:47:53 12:48:49 12:49:46 12:50:42 12:51:38 12:52:35
> 12:53:31
>  [17] 12:54:27 12:55:24 12:56:20 12:57:16 12:58:13 12:59:09 13:00:05
> 13:01:01
>  [25] 13:01:58 13:02:54 13:03:50 13:04:47 13:05:43 13:06:39 13:07:36
> 13:08:32
>  [33] 13:09:28 13:10:25 13:11:21 13:12:17 13:13:14 13:14:10 13:15:06
> 13:16:03
>  [41] 13:16:59 13:17:55 13:18:52 13:19:48 13:20:44 13:21:41 13:22:37
> 13:23:33
>  [49] 13:24:30 13:25:26 13:26:22 13:27:19 13:28:15 13:29:11 13:30:07
> 13:31:04
>  [57] 13:32:00 13:32:56 13:33:53 13:34:49 13:35:46 13:36:42 13:37:39
> 13:38:35
>  [65] 13:39:32 13:40:28 13:41:24 13:42:21 13:43:17 13:44:13 13:45:10
> 13:46:06
>  [73] 13:47:02 13:47:59 13:48:55 13:49:51 13:50:48 13:51:44 13:52:40
> 13:53:37
>  [81] 13:54:33 13:55:29 13:56:26 13:57:22 13:58:19 13:59:15 14:00:11
> 14:01:08
>  [89] 14:02:05 14:03:01 14:03:57 14:04:54 14:05:50 14:06:46 14:07:42
> 14:08:39
>  [97] 14:09:35 14:10:31 14:11:28 14:12:24 14:13:20 14:14:17 14:15:13
> 14:16:09
> [105] 14:17:06 14:18:02 14:18:58 14:19:55 14:20:51 14:21:47 14:22:44
> 14:23:40
> [113] 14:24:36 14:25:32 14:26:29 14:27:25 14:28:21 14:29:18 14:30:14
> 14:31:10
> 120 Levels: 12:39:26 12:40:22 12:41:19 12:42:15 12:43:11 12:44:08 ...
> 14:31:10
> >
> 
> Enjoying a little "R and R",
> 
> John
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 


********************************************************************** 
This is a commercial communication from Commerzbank AG.\ \ T...{{dropped}}




More information about the R-help mailing list