07.01.2013 Views

The Art of R Programming - Index of

The Art of R Programming - Index of

The Art of R Programming - Index of

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

54 CHAPTER 5. LISTS<br />

> lapply(list(1:3,25:27),median)<br />

[[1]]<br />

[1] 2<br />

[[2]]<br />

[1] 26<br />

In this example the list was created only as a temporary measure, so we should convert back to numeric:<br />

> as.numeric(lapply(list(1:3,25:27),median))<br />

[1] 2 26<br />

5.9 Size <strong>of</strong> a List<br />

You can obtain the number <strong>of</strong> elements in a list via length():<br />

> length(j)<br />

[1] 3<br />

5.10 Recursive Lists<br />

Lists can be recursive, i.e. you can have lists within lists. For instance:<br />

> b c a a<br />

[[1]]<br />

[[1]]$u<br />

[1] 5<br />

[[1]]$v<br />

[1] 12<br />

[[2]]<br />

[[2]]$w<br />

[1] 13<br />

> length(a)<br />

[1] 2<br />

So, a is now a two-element list, with each element itself being a list.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!