I have a list of lists with names, and I want to have a efficient way to delete duplicities, this is, I only want to preserve the first time a "word" appears (example: "hey"). This is the following code Im using right now.
del <- function(a,b){return(a[!a%in%b])}
for(i in 1:length(mcli)){
temp<-mcli[[i]]
mcli<-sapply(mcli,del,b=temp)
mcli[[i]]<-temp
#print(i)
}
The variable mcli is the list of lists:
mcli<-list()
mcli[[1]]<-c("hey","hou")
mcli[[2]]<-c("yei","hou")
mcli[[3]]<-c("yei","hey")
So the variable will be:
> mcli
[[1]]
[1] "hey" "hou"
[[2]]
[1] "yei" "hou"
[[3]]
[1] "yei" "hey"
This will generate empty lists inside the list of lists (the third list as all the words in it are duplicated from previous lists) , so at the end I run:
mcli<-Filter(Negate(function(X){length(X)==0}),mcli)
The result should be:
> mcli
[[1]]
[1] "hey" "hou"
[[2]]
[1] "yei"
Thank you in advance.
EDIT: SOLVED