So, I have a long list of objects, each of which has a slot that I want to delete. In particular, they store data in duplicate. But the reason does not matter.
My main question is what is the βrightβ way to do this. So here is the setup:
q <- list() q$useless <- rnorm(100) q$useful <- rnorm(100) SampleList <- list(q,q,q)
So, I have a list of identical objects (or at least identical view objects). I want to remove a useless slot. why, because it is useless to me.
I can do with the loop:
for (i in 1:length(SampleList)){ SampleList[[i]]$useless <- NULL }
But why is the lapply () version not working. So guess, the question is what I wonβt get about myself.
lapply(SampleList, function(x){print(x$useless) }) SampleList<- lapply(SampleList, function(x){x$useless <- NULL })
source share