[R] Reading and converting time data via read.table

Jim Lemon drjimlemon at gmail.com
Mon Jun 6 00:17:21 CEST 2016


Hi EKE,
Your problem may be that the date strings are being read as a factor.
Try using stringsAsFactors=FALSE when you read the data in. Another
way is to convert your dates to strings when passing to as.Date:

as.Date(as.character(mydf$Date),"%m/%d/%Y")

Jim


On Sun, Jun 5, 2016 at 10:53 PM, Ek Esawi <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