[R] plotting multiple animal tracks against Date/Time

Struve, Juliane j.struve at imperial.ac.uk
Mon Sep 27 16:01:55 CEST 2010


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)




From: Gabor Grothendieck [ggrothendieck at gmail.com]
Sent: 24 September 2010 22:08
To: Struve, Juliane
Cc: r-help at r-project.org
Subject: Re: [R] plotting multiple animal tracks against Date/Time


On Fri, Sep 24, 2010 at 4:16 PM, Struve, Juliane <j.struve at imperial.ac.uk> wrote:

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 
}





That was just an example.   The purpose of Lines was to make the example self contained and reproducible. In reality you dont use Lines at all.  Also your post suggested that they were in separate files since you had headings on each one.  If that is not the case then you just read it all at once using read.zoo.   z <- read.zoo(ReleaseDates.csv", split = "Fish_ID", header = TRUE, sep = ",", ...whatever...)


There are three vignettes (pdf documents) that come with zoo.  Read them all and read the help page of read.zoo.


More information about the R-help mailing list