[R] list indexing problem reading in files from a directory

stephen sefick ssefick at gmail.com
Tue Aug 11 19:45:43 CEST 2009


I am running into a problem with allocating these files to a list as
they are read in through a for loop.  I know I am probably doing
something wrong, but I can't figure out what.  I know this is not
reproducible.  I am ending up with a data frame of the very last file
to be read in.  I know it is in the indexing, but I can't wrap my head
around it.
thanks for all of the help,

Stephen Sefick



#level logger read in
read.ll <- function(path){
library(chron)
library(zoo)
list.of.files <- list.files(path)
length.files <- length(list.of.files)
	for(i in 1:length.files){
	df <- list()
	df[[i]] <- read.table(paste(sep="/", path, list.of.files[i]), skip=45)
	length.1 <- length(df[[i]][,1])
	length.2 <- length(df[[i]][,1])-1
	df[[i]] <- df[[i]][-c(length.1, length.2),]
	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]]))

	}
}

a <- read.ll("C:/Documents and Settings/Feminella
Lab/Desktop/WB_LL_Data/Wolf Bay Data/Raw solinist data/Compensated by
Brad")

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