[R] list with list function

Andras Farkas motyoc@k@ @end|ng |rom y@hoo@com
Mon Feb 4 22:01:06 CET 2019


Hello everyone,

wonder if you would have a thought on a function for the following:


we have

a<-sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"),5)
b<-sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 4)
c<-sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 3)

d<-c(1,3,5)
e<-c(1,4)
f<-c(1,2)

listA<-list(a,b,c)
listB<-list(d,e,f)


what I would like to do with a function (my real listA and listB can be of any length but always equal length, but their components like a,b,and c those can be unequal) as opposed to manually is to derive the following answer

listfinal<-list(a[-d],b[-e],c[-f])
listfinal


essentially the elements in listB serve as identifying the position of corresponding list element in listA and removing it from listA. 

these lists listA and listB in practice are columns of a data frame that I am trying to work with and were generated with a function using lapply...

appreciate any thoughts you may have to make this functional...

thanks,

Andras 



More information about the R-help mailing list