Statistical Analysis: an Introduction using R/R/Lists
Jump to navigation
Jump to search
Input:
Result:
R is very particular about what can be contained in a vector. All the elements need to be of the same type, an moreover must be either types of number[1], logical values, or strings of text[2].
If you want a collection of elements which are of different types, or not of one of the allowed vector types, you need to use a list.
![](http://upload.wikimedia.org/wikipedia/commons/thumb/7/72/Nuvola-inspired-terminal.svg/20px-Nuvola-inspired-terminal.svg.png)
l1 <- list(a=1, b=1:3)
l2 <- c(sqrt, log) #
![](http://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Crystal_Clear_app_kscreensaver.svg/20px-Crystal_Clear_app_kscreensaver.svg.png)
Notes
[edit | edit source]- ↑ There are actually 3 types of allowed numbers: "normal" numbers, complex numbers, and simple integers. This book deals almost exclusively with the first of these.
- ↑ This is not quite true, but unless you are a computer specialist, you are unlikely to use the final type: a vectors of elements storing "raw" computer bits, see
?raw