Skip to content
Prev 309287 / 398506 Next

naming datasubsets in a loop

Hello,

The best way of doing what you want is to save the subsets in a list.

subsets.list <- vector("list", 10)
for(i in 1:10)
     subsets.list[[i]] <- subset(...etc...)

names(subsets.list) <- names

You can also assign names using assign().


for(i in 1:10){
     sb <- subset(...etc...)
     assign(names[i], sb)
}


But this will create 10 different objects, the first way, using a list, 
keeps them all together.

Also, as you've seen, 'names' is an R function, choose something else 
for your variable name.

Hope this helps,

Rui Barradas
Em 29-10-2012 17:10, paladini escreveu: