[R] Formatting datetime data for gantt.chart.
Jim Lemon
jim at bitwrit.com.au
Sat Jul 31 13:55:53 CEST 2010
On 07/31/2010 03:12 AM, Andrew Noyes wrote:
>
> Overall goal:
>
> I'd like to have a visual representation of when certain computer applications are running over the course of a day (data will come from a SQL query later, but I'm using a csv for now). My idea is to use a gantt chart, but I'm running into issues with the start and end time. I'm wondering if it's because I need to use hours instead of days as my unit of time.
>
> Problem #1
> I'm trying to use strptime to convert a datetime string (7/12/2010 5:30:05 PM) to POSIX so I can use it as a start/end time in a gantt chart. ( I need to measure hours instead of days, so as.POSIXct/lt won't work for me. I'd also like to retain date info so I can create weekly/monthly averages))
>
> When tested, I get this:
>
>> strptime("7/12/2010 5:30:05 PM", "%X")
> [1] NA
try this:
strptime("7/12/2010 5:30:05 PM", "%d/%m/%Y %I:%M:%S %p")
>
> When I delete the date, I get:
>
>> strptime("5:30:05 PM", "%X")
> [1] "2010-07-30 05:30:05"
%X only specifies time
>
> The full date string in the first example seems pretty unambiguous, so I'm not sure why it is not being recognized and %X should show the full datetime string - any suggestions?
>
> #2
> I will read the data from a csv file (and eventually, a database). A secondary problem I've run into is converting the entire list of times - will I need to create a loop to handle them all or is there a function similar to tapply() that I can use?
>
Just pass the whole vector of dates as character strings - you'll get a
vector of date/time values.
Jim
More information about the R-help
mailing list