On Tue, 11 Aug 2009, stephen sefick wrote:
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()
move the above line to BEFORE the loop and you should be good to go.
HTH,
Chuck
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
______________________________________________
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.
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
______________________________________________
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.