Hi again,

when applying the code to my real data I need to deal with a large number of 
individuals and massive data sets. I am using the code below to read in the 
data for different individuals, and would like to create the "Lines" within the 
loop. But "Lines" needs to have the variable Fish_ID somehow included in the 
name, as otherwise the string will be overwritten on each execution. How can I 
create a different "Lines" for each Fish_ID ? Or is there a better way of doing 
this ? Sorry, this is surely a beginner's question.

Thank you very much for your help.

Regards,

Juliane

ReleaseDates <- read.csv(file="ReleaseDates.csv",head=TRUE,sep=",")
for (i in 1:length(ReleaseDates$Fish_ID)){
Fish_ID <- ReleaseDates$Fish_ID[i]
Data <- read.csv(paste(Fish_ID))
Lines <- paste(Data$Date,Data$Distance)
print Lines
}
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<http://www.aquaticresources.org/>



________________________________
From: Gabor Grothendieck [ggrothendi...@gmail.com]
Sent: 23 September 2010 23:06
To: Struve, Juliane
Cc: r-help@r-project.org
Subject: Re: [R] plotting multiple animal tracks against Date/Time

On Thu, Sep 23, 2010 at 5:53 PM, Struve, Juliane 
<j.str...@imperial.ac.uk<mailto:j.str...@imperial.ac.uk>> wrote:
Hello,

thank you very much for replying. I have tried this, but I get error message

"Error in .subset(x, j) : invalid subscript type 'list'" after

z1 <- read.zoo(textConnection(Lines1), skip = 1, index = list(1, 2), FUN = dt)

Regards,

Juliane


It works for me.  You likely have an outdated version of zoo.  Make sure you 
have zoo 1.6-4.  Here is the output:

> packageDescription("zoo")$Version
[1] "1.6-4"
>
> Lines1 <- "Date                    Distance [m]
+ 2006-08-18 22:05:15 1815.798
+ 2006-08-18 22:06:35 1815.798
+ 2006-08-18 22:08:33 1815.798
+ 2006-08-18 22:09:49 1815.798
+ 2006-08-18 22:12:50 1815.798
+ 2006-08-18 22:16:26 1815.798"
>
> Lines2 <- "Date                          Distance [m]
+ 2006-08-18 09:53:20      0.0
+ 2006-08-18 09:59:07      0.0
+ 2006-08-18 10:09:20      0.0
+ 2006-08-18 10:21:14      0.0
+ 2006-08-18 10:34:18      0.0
+ 2006-08-18 10:36:44    100.2"
>
> library(zoo)
> library(chron)
>
> # read in data
>
> dt <- function(date, time) as.chron(paste(date, time))
> z1 <- read.zoo(textConnection(Lines1), skip = 1, index = list(1, 2), FUN = dt)
> z2 <- read.zoo(textConnection(Lines2), skip = 1, index = list(1, 2), FUN = dt)
>
> # create single zoo object
>
> z <- na.approx(cbind(z1, z2), na.rm = FALSE)
Warning messages:
1: closing unused connection 4 (Lines2)
2: closing unused connection 3 (Lines1)
>
> # plot -- remove screen=1 if you want separate panels
>
> plot(z, screen = 1)




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


        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to