[R] Reading and converting time data via read.table
MacQueen, Don
macqueen1 at llnl.gov
Wed Jun 8 19:20:38 CEST 2016
As far as I know, base R does not have a class for storing times that are
not associated with a date, and recognizing that they are times. That
being the case, I don't think there is a way to convert them to some sort
of time class while reading them into R using read.table(). I would read
them into R as character strings, and then convert them (it would take
only a few extra lines of code). How you convert them depends on the next
question, which is:
What do you need to do with those times?
For example, are T1 and T2 the times associated with two events that both
occurred on the specified Date? If that is the case, I would probably form
two POSIXct variables by combining the Date with T1 and the Date with T2.
Or, do you just need to be able to sort your data by T1, or by T2? Or do
you need to calculate the time differences (such as T2-T1) to get the
number of minutes between those two times?
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 6/5/16, 5:53 AM, "R-help on behalf of Ek Esawi"
<r-help-bounces at r-project.org on behalf of esawiek at gmail.com> wrote:
>Hi All--
>
>
>
>I am relatively new to R. I am reading a csv file via read.table (MyFile).
>The data types in the file are date, string, integer, and time. I was able
>to read all the data and manipulated correctly except time, e.g., 12:30. I
>used as.Date to convert date and string and integer were easily done. I
>could not figure out how to convert the time data correctly. I tried chron
>but w/o success and I read that POSIXlt and POSIXct work only for date and
>time (e.g. 01/02/1999, 12:30:20). I did not try the lubridate package. Is
>there a way to read time data without date attached to it like mine?
>
>
>
>I am grateful for any help and thanks in advance‹EKE
>
>
>
>Here is an example of my data when read into R via read.table
>
>
>
> AA Date Name T1 T2
>N1
>
>1 312171 7/1/1995 OF 13:37 1:43 123
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list