[R] Converting factor data into Date-time format

David L Carlson dcarlson at tamu.edu
Tue Sep 30 22:43:14 CEST 2014

First, use stringsAsFactors=FALSE with the read.csv() function. That will prevent the conversion to factors. Then try to convert date and time to datetime objects. 

David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of tandi perkins
Sent: Tuesday, September 30, 2014 12:55 PM
To: r-help at r-project.org
Subject: [R] Converting factor data into Date-time format

Hello R help: 

I am
new to this forum so I apologize in advance for any protocol missteps.  I
have a data set that is comprised of eight birds with GPS; each of which
transmit everyday at 8:00 am, 4:00 pm, and midnight for 1 year (although I have
some missing relocation's).  I am trying to format my data to be run in
adehabitatLT but I am unsuccessful.  I have a "csv" file with
the following header: "Craneid, Date, Time, Long, Lat, Habitat,
BurstID".  R creates factor levels in the all of the data except Lat,
Long. I have attempted the following to correctly format my date and time
factors (data=l10): 


 datetime=as.POSIXct(paste(l10$Date, l10$Time), format="%m/%d/%Y
%H:%M:%S", "America/Chicago") 

coord=data.frame((l10$Longitude), (l10$Latitude)) 

test=as.ltraj(coord, datetime, l10$Craneid, burst=l10$ID, typeII=TRUE) 

in as.ltraj(coord, datetime, l10$Craneid, burst = l10$ID, typeII = TRUE) : 

non unique dates for a given burst 

researched this error on the list serve and found that I could have duplicates
so I checked for duplicates in datetime and the return was NULL (I also check
for duplicates in Excel as I am in the learning stages in R).  Next I read
a thread posted on the R help in 2012 with a similar problem so I attempted
what was suggested as follows: 

 datetime=as.POSIXct(strptime(as.character(l10$Date, l10$Time),
format="%m/%d/%Y %H:%M:%S")) 

datetime, l10$Craneid, burst=l10$ID, typeII=TRUE) 

Same error. 

I have tried: 

format="%m/%d/%Y %H:%M:%S")[l10$Date][l10$Time] 

in as.POSIXct(as.character(levels(l10$Date)(l10$Time)), format = "%m/%d/%Y
%H:%M:%S") : 

attempt to apply non-function 

someone please explain what I am doing wrong?  My goal is to obtain
trajectories for all birds using each bird as a burst as is detailed in the
adehabitatLT manual and then to create Bias Random Bridges for each bird.
 I did not include my data but I can if that will be helpful. 

you in advance for your help,


	[[alternative HTML version deleted]]

R-help at r-project.org mailing list
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