[R] merge zoo objects contained in a list

stephen sefick ssefick at gmail.com
Wed Aug 12 15:04:46 CEST 2009


All of the data frames in the list (list of 74)  have the same column
names, and some have the exact same index values, while others have
out of sync, but in the same range.  I can send a small example off
list.  I will look at it again when I get into work this morning to
see if I can fix it.
thanks for all of the help,

Stephen Sefick

On Tue, Aug 11, 2009 at 6:33 PM, Gabor
Grothendieck<ggrothendieck at gmail.com> wrote:
> 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.
>>
>



-- 
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




More information about the R-help mailing list