Reputation: 1769
This code
d <- 5
for(i in 1:10) {
nam <- paste("S", i, sep = "")
assign(nam, rnorm(3)+d)
}
builds variables A1, A2,A3...A10
changing variable name in a for loop. My question is: how do i delete all these variables (with only one instruction) from memory without touching the other environment variables? (I'm using RStudio)
Upvotes: 0
Views: 36
Reputation: 887048
If we want to remove those variables, just use the same syntax with paste
and as paste
is vectorized it can create a vector of object names which can be fed into the rm
with list
argument
rm(list = paste0("S", 1:10))
Upvotes: 2