[R] merge zoo objects contained in a list

Gabor Grothendieck ggrothendieck at gmail.com
Wed Aug 12 01:33:45 CEST 2009


Can you provide something reproducible and elaborate on
what "expected" means.

On Tue, Aug 11, 2009 at 4:11 PM, stephen sefick<ssefick at gmail.com> wrote:
> I would like to merge zoo objects that are stored in a list into one
> big zoo object with one index for all of the observations.
>
> I have created the list (74 dataframes) with the code below, and have
> tried the do.call(merge, foo) in the call and the output is not what I
> expected.  Any help would be greatly appreciated.
>
> Stephen Sefick
>
> ###################################################level logger read
> in#############################################
> read.ll <- function(path, file.name)
>        {
> if(!require(chron))
>   stop("Package 'chron' required but not installed.")
> if(!require(zoo))
>   stop("Package 'zoo' required but not installed.")
> list.of.files <- list.files(path)
> length.files <- length(list.of.files)
> df <- vector(mode = "list", length = length.files)
> fnames <- paste(path, list.of.files, sep = "/")
>
>                for(i in seq(along = list.of.files))
>                {
>                df[[i]] <- read.table(fnames[i], skip=45, as.is=TRUE)
>                #lengths of the dataframes because the last to lines of the .lev
> file are garbage#
>                length.1 <- length(df[[i]][,1])
>                length.2 <- length(df[[i]][,1])-1
>                #remove the garbage
>                df[[i]] <- df[[i]][-c(length.1, length.2),]
>                #make chron class for datetime
>                df[[i]] <- data.frame(chron(as.character(df[[i]][,1]),
> as.character(df[[i]][,2]), format=c(dates="Y/m/d", times="H:M:S")),
> as.numeric(df[[i]][,3]), as.numeric(df[[i]][,4]),
> as.factor(list.of.files[[i]]))
>                #change names of columns
>                names(df[[i]]) <- c("datetime", "level", "temp", "site")
>                #make zoo object
>                df[[i]] <- zoo(df[[i]], df[[i]][,"datetime"])
>                }
>                        #merge all of the lists into one huge dataframe
>                        merged <- do.call(merge, df)
>
>
> return(merged)
> }
> --
> Stephen Sefick
>
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods.  We are mammals, and have not exhausted the
> annoying little problems of being mammals.
>
>                                                                -K. Mullis
>
> ______________________________________________
> R-help at 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.
>




More information about the R-help mailing list