On Dec 20, 2009, at 2:40 PM, Muhammad Rahiz wrote:
Hi all,
How can I overcome the error "object of type 'closure' not
subsettable"
I ran the following script
seq <- paste(seq(1914, 1916, by=1), "*.y", sep=".") # make sequence
c <- 3 # total number of files
d2 <- file # creates dummy file
# Input sequence in loop
for (i in 1:3){
list <- list.files("~/ukcp09/txt/x.djf", seq[[i]])
file <- lapply(list, read.table)
# Calculations
mean <- (Reduce("+", file))/c
d2[[i]] <- file[[i]] - mean
Apparently, the following command is the source of the error.
d2[[i]] <- file[[i]] - mean
It works OK when I typed into the terminal the following after
running the script.
> for (j in 1:3) print (file[[j]]-mean)
Generally R is able to keep straight what is a vector and what is a
function but you are using quite a few names for vectors and lists
which should be reserved (at least in your head) for functions. Here
is a list of function names to avoid as object names:
c
file
list
seq
mean
Why not try being so ambiguous? ObF: Would you call your dog "dog"?
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
______________________________________________
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.