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 vector
s 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 vector
were eliminated.
I ask you:
- why
mylist
was eliminated andcluster
remained (both havetypeof
list
)? - why a class object
list
was eliminated, as occurred withmylist
(I specifiedvector
as 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 argumentmode
that 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 sametypeof
ofmylist
(i and..,list
) and this is eliminated.– neves