Your data
df <- list(structure(list(a = 1:5, b = 6:11), .Names = c("a", "b")), structure(list(a = 6:11, b = 1:5), .Names = c("a", "b")), structure(list(a = 12, b = 12), .Names = c("a", "b")))
This gives you unique values ββfor nested lists:
library(plyr) df.l <- llply(df, function(x) unlist(unique(x))) R> df.l [[1]] [1] 1 2 3 4 5 6 7 8 9 10 11 [[2]] [1] 6 7 8 9 10 11 1 2 3 4 5 [[3]] [1] 12
EDIT
Thanks to Ramnath, I changed the code a bit and hope this answer matches the needs of your question. For illustration, I also retain the previous answer. A little modified data now has an extra list.
df <- list(structure(list(a = 1:5, b = 6:11), .Names = c("a", "b")), structure(list(a = 6:11, b = 1:5), .Names = c("a", "b")), structure(list(a = 12, b = 12, c = 10:14), .Names = c("a", "b", "c"))) fx <- function(x.list) { x.names <- names(x.list) i <- combn(x.names, 2) l <- apply(i, 2, function(y) x.list[y]) llply(l, unlist) }
Now you can apply this function to your data.
all.l <- llply(df, fx) llply(all.l, function(x) llply(x, unique)) R> [[1]] [[1]][[1]] [1] 1 2 3 4 5 6 7 8 9 10 11 [[2]] [[2]][[1]] [1] 6 7 8 9 10 11 1 2 3 4 5 [[3]] [[3]][[1]] [1] 12 [[3]][[2]] [1] 12 10 11 13 14 [[3]][[3]] [1] 12 10 11 13 14
However, the nested structure is not very user friendly. It may be slightly modified ...