I have a huge nested list of 15 levels. I need to replace empty lists occurring at any level with chr "". I tried iterating over the list, but it does not work. is there an easy way to do this?
nested_list<-list(a=list(x=list(),y=list(i=list(),j=list(p=list(),q=list()))),b=list())
lapply(nested_list,function(x) if(length(x)==0) "" else x)
lapply applies only to the first level, how do I recursively iterate over the entire nested list and perform this action?
source
share