Skip to content

how to setdiff on lists of lists

3 messages · Simone Gabbriellini, PIKAL Petr, jim holtman

#
Dear List,

I have a data structure like:
[[1]]
[1] 1 2 3

[[2]]
[1] 4 5 6
[[1]]
[1] 3

[[2]]
[1] 5

I would like to set differences between "aa" and "bb" and get as
result another list of lists like:
[[1]]
[1] 1 2

[[2]]
[1] 4 6

I am trying:

lapply(aa, setdiff, bb)

but I simply get "aa" back as result. Could you please point me in the
right direction about the combination of functions that I need to
accomplish this task?

Best regards,
Simone
#
Hi

you have something wrong in your R session, works for me.
[[1]]
[1] 1 2 3

[[2]]
[1] 4 5 6
[[1]]
[1] 3

[[2]]
[1] 5
[[1]]
[1] 1 2

[[2]]
[1] 4 6

Regards
Petr
#
You can also try 'mapply'
[,1] [,2]
[1,]    1    4
[2,]    2    6
On Fri, Feb 1, 2013 at 5:16 AM, Simone Gabbriellini
<simone.gabbriellini at gmail.com> wrote: