On Mon, Sep 27, 2010 at 10:01 AM, Struve, Juliane
<j.str...@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

______________________________________________
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