[R] Converting factor data into Date-time format

PIKAL Petr petr.pikal at precheza.cz
Wed Oct 1 06:35:23 CEST 2014


Hi

Everything seems to be OK. Please check your if your objects are as required by.

str(objects) (and post result if you are in doubt :)

from your attempts I presume that datetime was not created properly
Maybe this can do it, without actual data it is hard to tell exactly.

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

BTW, factors can be converted to POSIX class the same way as character vectors are.

Regards
Petr

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of David L Carlson
> Sent: Tuesday, September 30, 2014 10:43 PM
> To: tandi perkins; r-help at r-project.org
> Subject: Re: [R] Converting factor data into Date-time format
>
> 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):
>
>
>
> First
> attempt:
>
> 1.
>  datetime=as.POSIXct(paste(l10$Date, l10$Time), format="%m/%d/%Y
> %H:%M:%S", "America/Chicago")
>
>
>
> 2.
> coord=data.frame((l10$Longitude), (l10$Latitude))
>
>
>
> 3.
> test=as.ltraj(coord, datetime, l10$Craneid, burst=l10$ID, typeII=TRUE)
>
>
>
> Results:Error
> in as.ltraj(coord, datetime, l10$Craneid, burst = l10$ID, typeII =
> TRUE) :
>
>
> non unique dates for a given burst
>
>
>
> I
> 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:
>
>
>
> 1.
>  datetime=as.POSIXct(strptime(as.character(l10$Date, l10$Time),
> format="%m/%d/%Y %H:%M:%S"))
>
>
>
> 2.test=as.ltraj(coord,
> datetime, l10$Craneid, burst=l10$ID, typeII=TRUE)
>
>
>
> Results:
> Same error.
>
>
>
> Finally,
> I have tried:
>
>
>
> 1.
>  datetime=as.POSIXct(as.character(levels(l10$Date)(l10$Time)),
> format="%m/%d/%Y %H:%M:%S")[l10$Date][l10$Time]
>
>
>
> Results:Error
> in as.POSIXct(as.character(levels(l10$Date)(l10$Time)), format =
> "%m/%d/%Y
> %H:%M:%S") :
>
>
> attempt to apply non-function
>
>
>
> Can
> 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.
>
>
>
> Thank
> you in advance for your help,
>
> TLP
>
>
>       [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.

________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.


More information about the R-help mailing list