Recursive or non-recursive list

In R, lists can be recursive, which means that you can have list within list.

> c(list(a=1, b=2, c=list(d=4, e=5)))
[1] 1

[1] 2

[1] 4

[1] 5

The code above creates a two-component list, with c component of the main list itself being another list.

However, sometimes you may want to create a single list instead of a recursive list. You can do this by setting the optional argument recursive in c() function to TRUE. (It’s weird that setting recursive to TRUE actually gives you a non-recursive list.)

> c(list(a=1, b=2, c=list(d=4, e=5)), recursive=T)
  a   b c.d c.e
  1   2   4   5


Reference: The Art of R Programming by Norman Matloff

Posted in R Programming Tips.

One Comment

  1. The kid-friendly IDE is a big deal, because it is an angloaue to the instant-on basics of the past. I would LOVE a lua, python, javascript, haskell, or pascal version of the same. Something with real data structures. *shrug* Time and skill at design keep me from writing such a thing myself. Although, the Qt Creator with QML might make it easy to write a javascript one.

Leave a Reply

Your email address will not be published. Required fields are marked *