[R] plotting multiple animal tracks against Date/Time
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Sep 29 14:45:13 CEST 2010
On Wed, Sep 29, 2010 at 7:52 AM, Struve, Juliane
<j.struve at 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"))
FUN is an argument of lapply so what is actually running is
lapply(filenames, FUN = as.chron, ...)
rather than
lapply(filenames, FUN = read.zoo, ...).
It seems the short form usage of lapply won`t work here. Try this instead:
lapply(filenames, function(F) read.zoo(F, header = TRUE, sep = ",",
FUN = as.chron,
colClasses = c("NULL", "NULL", "character", "numeric")))
--
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