What does rm remove? We had a diamonds dataset with a column
called carat. I then created a copy of carat by changing its first
element to 45.
diamonds <- read.table("http://www.amstat.org/publications/jse/datasets/4c.dat")
names(diamonds) <- c("carat","color","clarity", "cert", "price")
summary(diamonds$carat)
attach(diamonds)
summary(carat) ## same as above. attach lets us drop the diamonds$
carat[1] <- 45 ## creates a new copy of carat in the local workspace
summary(carat) ## finds the new copy first, so max is 45
rm(carat) ## removes the new copy from local workspace
summary(carat) ## finds the carat column in the attached dataset, max = 1.1
rm removes things from the local workspace, not from an attached
dataset. Similarly, changing something after attaching creates a
new copy and does not modify the original.