[R] Creating "%d/%m/%Y %H:%M:%S" format from separate date andtimecolumns
macqueen1 at llnl.gov
Thu Apr 18 21:09:55 CEST 2013
I know this is a late response, but what about
startt <- as.POSIXct( paste(data2$V4, data2$V5) )
endt <- startt + data2$V6
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
On 4/12/13 12:09 AM, "Cat Cowie" <cat.e.cowie at gmail.com> wrote:
>Thanks for your quick reply - this, in combination with reversing the
>date as it is shown in my data, worked perfectly.
>startt<- strptime((paste(data2$V4, data2$V5)), "%Y-%m-%d %H:%M:%S")
>Apologies for the silly question it seems, but you've saved me a lot
>of time. Always learning....
>On 12 April 2013 15:00, Gerrit Eichner
><Gerrit.Eichner at math.uni-giessen.de> wrote:
>> Hello, Cat,
>> see inline below.
>> Hth -- Gerrit
>> On Fri, 12 Apr 2013, Cat Cowie wrote:
>>> Hi R forum,
>>> Each row of my data (below) show a new contact event between animals.
>>> In order to ultimately look at the patterns of intervals between
>>> contacts, I need to calculate a contact end time. The contact starts
>>> at the date and time shown in V4 and V5, and lasts for the duration
>>> shown IN SECONDS in V6:
>>>> data2<- read.csv(file=file.choose(), header=F, sep=" ")
>>> V1 V2 V3 V4 V5 V6
>>> 1 3 PO4 CO1 2011-04-29 07:27:21 28
>>> 2 3 PO4 CO1 2011-04-24 05:57:39 20
>>> 3 3 PO4 CO1 2011-04-14 10:29:49 4
>>> 4 3 PO4 CO1 2011-04-16 07:27:31 63
>>> 5 3 PO4 CO1 2011-04-18 15:46:20 1
>>> 6 3 PO4 CO1 2011-04-18 15:45:57 1
>>> To start with I have tried to make the start data and time into one new
>>> startt<- strptime((paste(data2$V4, data2$V5)), "%d/%m/%Y %H:%M:%S")
>> Shouldn't you use "-" instead of "/" as it is used in data$V4?
>>> This executes without any warnings, but returns a full column of NA
>>> values. It would be great to fix this, and then to know how to
>>> correctly add column V6 as seconds to the resulting column.
>>> The problem is further exacerbated by an error with dput() with this
>>> data. It's a large dataset of over 9000 rows, and when I call:
>>> It returns dput(), but for all the data (i.e. not the first 50 rows).
>>> This of course does not fit on the workstation screen and therefore I
>>> cannot find out what class it has assigned to any of the data. The
>>> times appear sorted, suggesting they are being classed as a factor?
>>> Sorry I can't provide dput() data!
>>> Thanks, Cat
>>> R-help at r-project.org mailing list
>>> PLEASE do read the posting guide
>>> and provide commented, minimal, self-contained, reproducible code.
>R-help at r-project.org mailing list
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help