Klaus
Klaus

Reputation: 2056

Access nested structure

Are there some nice designs to call data in a nested structure e.g.

a<-list(list(LETTERS[1:3],LETTERS[1:3]),list(LETTERS[4:6]))
lapply(a,function(x) lapply(x, function(x) x)) 

but unlist is not a option.

Upvotes: 1

Views: 467

Answers (2)

Jilber Urbina
Jilber Urbina

Reputation: 61214

Not as good as @SimonO101's answer but just for providing as an alternative you can do it using do.call

> do.call(c,do.call(c, a))
[1] "A" "B" "C" "A" "B" "C" "D" "E" "F"

Also using Reduce

> do.call(c, Reduce(c, a))
[1] "A" "B" "C" "A" "B" "C" "D" "E" "F"

Upvotes: 1

Simon O&#39;Hanlon
Simon O&#39;Hanlon

Reputation: 60000

Recursive lapply... a.k.a rapply?

rapply( a , c )
[1] "A" "B" "C" "A" "B" "C" "D" "E" "F"

Upvotes: 1

Related Questions