Skip to content
Prev 363496 / 398502 Next

Loop over folder files

I still find the behavior of R's `for`-loop to be rather puzzling. In this case you appear to be getting the operation done, but because you didn't assign those table values to a variable they just disappeared.

Try this:

XXX <- list()

for (i in 1:length(fuente)){
   xxx=read_dta(fuente[i])
   XXX[[i]] <- table(xxx$cise, xxx$sexo)
   rm(xxx)
}
str(XXX)

Seems to me that if you can do assignment to the parent environment (without actually using assign( ..., env=...)  that you should also be able to see the results of evaluation occurring inside the for loop, but for-loops return NULL. So you see nothing.

David.
David Winsemius
Alameda, CA, USA