[R] plotting multiple animal tracks against Date/Time

Struve, Juliane j.struve at imperial.ac.uk
Mon Sep 27 23:38:24 CEST 2010


Hello,

thank you very much for replying. The code yields an error message 

Error in strptime(x, format, tz = tz) : invalid 'x' argument

But I can't see what's wrong with it, the Date/Time info  is in the third column, format is 
"%Y-%m-%d %H:%M:%S". There is no time zone info in the data, could this be a problem ?

Regards,

Juliane 

Dr. Juliane Struve
Daphne Jackson Fellow
Imperial College London
Department of Life Sciences
Silwood Park Campus
Buckhurst Road
Ascot, Berkshire,
SL5 7PY, UK

Tel: +44 (0)20 7594 2527
Fax: +44 (0)1344 874 957

http://www.aquaticresources.org
________________________________________
From: Gabor Grothendieck [ggrothendieck at gmail.com]
Sent: 27 September 2010 15:23
To: Struve, Juliane
Cc: r-help at r-project.org
Subject: Re: [R] plotting multiple animal tracks against Date/Time

On Mon, Sep 27, 2010 at 10:01 AM, Struve, Juliane
<j.struve at imperial.ac.uk> wrote:
> Hi,
>
> I am sorry that my question wasn not very clearly formulated.  My real data comes in 47 .csv files, one for each of 47 individual, for example:
>
> "","Fish_ID","Date","R2sqrt"
> "1",1646,2006-08-18 08:48:59,0
> "2",1646,2006-08-18 09:53:20,100
>
> I would like to read the data for all individuals in the for loop below and then combine them in a zoo object in order to plot them together.  My question is : How do I need to set up the for loop to deal with several individuals ? I have put question marks the bits that I am missing.
>
>  I very much appreciate your help.
>
> Regards,
>
> Juliane
>
>
> ReleaseDates <- read.csv(file="ReleaseDates",head=TRUE,sep=",")
> #reads in the individuals and their release dates
>
> for (i in 1:length(ReleaseDates)){
>  Fish_ID <- ReleaseDates$Fish_ID[i]
>  ??? <- read.zoo(file=paste("Results",Fish_ID,sep="_"),index.column=3,header=TRUE,FUN=as.chron,sep=",")
> #reads in data for each in Fish_ID
> }
>  z <- na.approx(cbind(???), na.rm = FALSE)
> plot(z)
>

Try this (untested):

library(zoo)

filenames <- paste("Results", ReleaseDates$Fish_ID, sep = "_")

# list of zoo objects removing 1st two columns in each file

Lz <- lapply(filenames, read.zoo, header = TRUE, FUN = as.chron,
  sep = ",", colClasses = c("NULL", "NULL", "character", "numeric"))

z <- do.call("merge", Lz)
colnames(z) <- as.character(ReleaseDates$Fish_ID)

# plot in single panel
plot(na.approx(z), screen = 1)


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com


More information about the R-help mailing list