Removing attributes of columns in data.frames on multilevel lists in R
This is perhaps too late to answer on this thread, but I wanted to share.
Two solutions : 1. function stripAttributes from merTools package.
to remove the attribute ATT from variable VAR in your data-frame MyData:
attr(MyData$VAR, "ATT") <- NULL
If you want to remove several attributes of all variables :
For (var in colnames(MyData)) {
attr(MyData[,deparse(as.name(var))], "ATT_1") <- NULL
attr(MyData[,deparse(as.name(var))], "ATT_2") <- NULL
}
I hope This Helps, Regards
You could write a function that works on one entry in the list, e.g.
one_entry <- function(x) {
for (i in length(x)) attr(x[[i]], "names") <- NULL
return(x)
}
and then run lapply
:
lapply(my_list, FUN=one_entry)
where mylist
is the data structure in the question.
It's a hack but worked in my case.
lapply(my_list, FUN=function(x){data.frame(as.matrix(x),stringsAsFactors = F)})