Hi all,

I've got a list of files from 1914 to 2000. For each file, I can call the 
read.table function as follows.

file <- read.table("1914.txt")


But I want to make a script so that at the end of the loop, the script selects 
the file 1915.txt, 1916.txt and so on.

I've used seq() to create the increment

seq <- paste(seq(1914, 2006, by=1), "*.txt.h", sep=".")

But it didn't work.

Below is the script;

seq <- paste(seq(1914, 2006, by=1), "*.txt", sep=".")

for (i in 1:93){
list <- list.files("~/ukcp09/txt/x.djf", seq)
file <- lapply(list, read.table)

mean <- (Reduce("+", file))/3
}

When I call

> objects()
> list
[1] "2006.01.txt.h" "2006.02.txt.h" "2006.12.txt.h"

The listed files are the last files in the sequence.

Am I doing the loop correctly?

--
Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling                
                        
Climate Research Laboratory, School of Geography & the Environment  
Oxford University Centre for the Environment
South Parks Road, Oxford, OX1 3QY, United Kingdom Tel: +44 (0)1865-285194 Mobile: +44 (0)7854-625974
Email: muhammad.ra...@ouce.ox.ac.uk

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

Reply via email to