[R] Creating "%d/%m/%Y %H:%M:%S" format from separate date and time columns

Cat Cowie cat.e.cowie at gmail.com
Fri Apr 12 08:50:25 CEST 2013


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=" ")
> head(data2)
  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 column:

startt<- strptime((paste(data2$V4, data2$V5)), "%d/%m/%Y %H:%M:%S")


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:

dput(head(data2,50))

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



More information about the R-help mailing list