[R] histogram of time-stamp data

Rui Barradas ruipbarradas at sapo.pt
Tue Jul 17 10:37:28 CEST 2012


Hello,

That's not the error I've had. You must be aware that read.table creates 
a data.frame and therefore the object 'timestamps' is NOT holding time 
stamps, it's holding a vector, 'V1', of time stamps.


timestamps <- read.table(text="
12:19:00
09:30:00
16:56:00
01:56:00
10:44:00
10:31:00
02:14:00
05:05:00
12:52:00
21:50:00
", stringsAsFactors=FALSE)
str(timestamps)

timestamps <- as.POSIXct(timestamps$V1, format="%H:%M:%S")  # here

h1 <- cut(timestamps, breaks="hour")
h2 <- cut(timestamps, breaks="15 mins")

op <- par(mfrow=c(1, 2))
hist(as.integer(h1))
hist(as.integer(h2))
par(op)


And the rest works.

Rui Barradas

Em 17-07-2012 07:11, e-letter escreveu:
> On 16/07/2012, Rui Barradas <ruipbarradas at sapo.pt> wrote:
>> Hello,
>>
>> Em 16-07-2012 22:45, e-letter escreveu:
>>> On 16/07/2012, r-help-request at r-project.org
>>>    <r-help-request at r-project.org> wrote:
>>>    > ------------------------------
>>>    >
>>>    > Message: 77
>>>    > Date: Mon, 16 Jul 2012 10:48:39 +0100
>>>    > From: Rui Barradas <ruipbarradas at sapo.pt>
>>>    > To: e-letter <inpost at gmail.com>
>>>    > Cc: r-help at r-project.org
>>>    > Subject: Re: [R] histogram of time-stamp data
>>>    > Message-ID: <5003E377.3000604 at sapo.pt>
>>>    > Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>>>    >
>>>    >
>>>    > timestamps <- as.POSIXct(Sys.Date()) + sample(24*60*60, 1e3, TRUE)
>>>    >
>>>
>>>    Why is it necessary to apply the sample to the current date? Looking
>>>    at the dataframe, I noticed that values have been changed:
>>
>> No! That instruction is just to create a data example with more
>> date/time values, in this case with a total of 1e3 different values.
>> What's important is the way to plot the histogram, namely, the cut()
>> with two example time periods, and that hist() needs numbers, not cut's
>> levels.
>>
>
> With the original data provided, R reports an error, that "'x' must be numeric'.
>



More information about the R-help mailing list