Skip to content
Prev 260140 / 398502 Next

Using a sting in variable names

olafgy <olafgy <at> gmail.com> writes:
http://r.789695.n4.nabble.com/Using-a-sting-in-variable-names-tp3527318p3527318.html
why don't you use a list (?list)?  This is particularly useful if each file is
formatted in the same way (ie. if they have the same columns, in the same order,
etc.), but this is not a necessity. 

Read each file as an separate item in the list.  That way if you want to compute
the same statistic on each of your files, you can use lapply on the each item of
the list.  I think this way save memory, but not totally sure on it.

Example:
X <- 1:100
vpn <- vector(mode = "list", length = length(X))

for(i in 1:length(X)){
vpn[[i]] <- read.table(paste("vpn", X[i], ".dat", sep =""))
}

HTH,
Ken