6
Consider the objects:
for(i in 1:6){
names<-paste0("var",i)
assign(names,runif(30,20,100))
}
dataset<-do.call(
cbind.data.frame,
mget(ls(pattern='*v'))
)
cluster<-kmeans(dataset,centers=3)
dataset$kmeans<-as.factor(cluster[['cluster']])
mylist<-split(dataset,dataset$kmeans)
names(mylist)<-paste('dataset',seq_along(mylist),sep='')
I tried to eliminate ONLY the vectors of globalenv():
rm(list=ls(Filter(is.vector,mget(ls()))))
But, the objects dataset (one data.frame) and cluster (one list) remain in the globalenv().
However, mylist and the vectorwere eliminated.
I ask you:
- why
mylistwas eliminated andclusterremained (both havetypeoflist)? - why a class object
listwas eliminated, as occurred withmylist(I specifiedvectoras an argument)?
You won’t be able to write an answer now. But the tip is here. Lists are a generic vector. The other vectors are atomic vectors.
– Tomás Barcellos
The function
is.vector()has an argumentmodethat can receive thetypeof(x)basic or "list" or "Expression" or "any". See?is.vector.– Tomás Barcellos
But why the object
cluster(onelist) still remains. He possesses the sametypeofofmylist(i and..,list) and this is eliminated.– neves