Hi: This 'works' on the lapply end:
# Function to read one file from the list: g <- function(x) read.zoo(file = x, header = TRUE, FUN = as.chron, sep = ",", colClasses = c("NULL", "NULL", "character", "numeric")) # Apply to all files in list: lapply(filenames, g) [[1]] (01/01/04 00:01:00) 100 # Just to prove to myself that this works on a list of input files, write.csv(Test,file="Test2") write.csv(Test,file="Test3") filenames <- c('Test', 'Test2', 'Test3') lapply(filenames, g) [[1]] (01/01/04 00:01:00) 100 [[2]] (01/01/04 00:01:00) 100 [[3]] (01/01/04 00:01:00) 100 Hope this helps, Dennis On Wed, Sep 29, 2010 at 4:52 AM, Struve, Juliane <j.str...@imperial.ac.uk>wrote: > I will post the example again to see if its readable now. My question is > why > does read.zoo(file=filenames,....) work and lapply(filenames, > read.zoo,...) does not ? Since I am reading the same file in both statements > I just do not know how to interpret "Error in strptime(x, format, tz = tz) : > invalid 'x' argument". > > Thank you for all help. > > Juliane > > library(chron) > library(zoo) > #Generate example file > Fish_ID=1646 > Date <- "01/01/2004 00:01:00" > Date <- as.POSIXct(strptime(Date,format="%m/%d/%Y %H:%M:%S")) > R2sqrt <-100 > Test <- data.frame(Fish_ID=Fish_ID,Date=Date,R2sqrt=R2sqrt) > write.csv(Test,file="Test") > #Read in example file > filenames="Test" > read.zoo(file=filenames, header = TRUE, FUN = as.chron, sep = ",", > colClasses = c("NULL", "NULL", "character", "numeric")) > lapply(filenames, read.zoo, header = TRUE, FUN = as.chron, sep = ",", > colClasses = c("NULL", "NULL", "character", "numeric")) > > ________________________________________ > From: Gabor Grothendieck [ggrothendi...@gmail.com] > Sent: 29 September 2010 00:09 > To: Struve, Juliane > Cc: r-help@r-project.org > Subject: Re: [R] plotting multiple animal tracks against Date/Time > > On Tue, Sep 28, 2010 at 9:30 AM, Struve, Juliane > <j.str...@imperial.ac.uk> wrote: > > > > Hi, > > > > in this self-contained example the file the same error message appears as > when I read in my original results files. > > > > library (zoo) > > library(chron) > > #generate example data > > Fish_ID=1646 > > Date <- "01/01/2004 00:01:00" > > Date <- as.POSIXct(strptime(Date,format="%m/%d/%Y %H:%M:%S")) > > R2sqrt <-100 > > #put into dataframe > > Test <- data.frame(Fish_ID=Fish_ID,Date=Date,R2sqrt=R2sqrt) > > # write .csv file > > write.csv(Test,file="Test") > > #generate list of files > > filenames="Test" > > #read file(s) into zoo object > > read.zoo(file=filenames, header = TRUE, FUN = as.chron, sep = ",", > colClasses = c("NULL", "NULL", "character", "numeric")) #works fine > > #read list of files into zoo.object > > lapply(filenames, read.zoo, header = TRUE, FUN = as.chron, sep = ",", > colClasses = c("NULL", "NULL", "character", "numeric"))# error > > "Error in strptime(x, format, tz = tz) : invalid 'x' argument" > > > > Am I missing something ? > > > > Thank you for your time and patience. > > Self contained means anyone else can just copy your code and paste it > into their session and see the error message you see. > > Its likely that your file does not contain what you think it does. > > > > -- > 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. > [[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.