[R] need to delete by time, not date

Adele_Thompson at cargill.com Adele_Thompson at cargill.com
Tue May 10 18:07:21 CEST 2011


Good deal. I will do that in the future. Thanks.

-----Original Message-----
From: dwinsemius at comcast.net [mailto:dwinsemius at comcast.net] 
Sent: Tuesday, May 10, 2011 10:45 AM
To: Thompson, Adele - Adele_Thompson at cargill.com
Cc: r-help at r-project.org
Subject: Re: [R] need to delete by time, not date


On May 10, 2011, at 11:23 AM, Adele_Thompson at cargill.com wrote:

> Thanks, that did exactly what I wanted. I realize that I didn't put  
> it in the best form, but was having trouble coming up with a  
> replicable example. I see that many people here quickly create  
> examples and I am learning how to do that, but still struggle,  
> especially when using as.POSIXct and other more complex classes.

Excuse not accepted. All you needed to do with Mat1 was dput(Mat1). Or  
if your real data object was a lot longer, then just dput(head(Mat1,  
10)).

-- 
David.
> Thanks for the help.
>
> -----Original Message-----
> From: dwinsemius at comcast.net [mailto:dwinsemius at comcast.net]
> Sent: Tuesday, May 10, 2011 10:19 AM
> To: Thompson, Adele - Adele_Thompson at cargill.com
> Cc: r-help at r-project.org
> Subject: Re: [R] need to delete by time, not date
>
>
> On May 10, 2011, at 11:06 AM, Schatzi wrote:
>
>> I have a matrix where one column has a date and another column has a
>> time. I
>> need to delete all times before 6am. I had combined the Date and
>> Time column
>> into DateTime.
>>
>> Mat1:
>> Weight     Date  Time
>> 7.6 04/28/11 09:03
>> 8.4 04/29/11 03:11
>> 8.6 04/29/11 05:32
>> 8.6 04/29/11 09:53
>> 1.4 05/01/11 19:52
>>
>> I tried just picking up the time:
>>
>> as.POSIXct(Mat1$Time, format = "%H:%M")
>>
>> but this assigns the time value today's date.
>
> Since these are either character strings (or factors) at the
> moment ... and if they are matrices they are character...
>
> Mat1[Mat1$Time >= "06:00" , ]
>
> If actually a dataframe then
>
> Mat1[as.character(Mat1$Time) >= "06:00" , ]
>
> In the future please include the output of dput(Mat1).
>
>>
>> The final matrix should look like:
>> Weight     Date  Time
>> 7.6 04/28/11 09:03
>> 8.6 04/29/11 09:53
>> 1.4 05/01/11 19:52
>>
>>
>
> David Winsemius, MD
> West Hartford, CT
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list