Listas
# -----------------------------------------------------------------------------
# Listas
# -----------------------------------------------------------------------------
# Gerando listas
#list() esta é a função
l1 = list(c(2, 6, 8),
matrix(seq(1, 4),
ncol = 2),
'ivan')
l1
## [[1]]
## [1] 2 6 8
##
## [[2]]
## [,1] [,2]
## [1,] 1 3
## [2,] 2 4
##
## [[3]]
## [1] "ivan"
dad1 = data.frame(var1 = rnorm(10),
var2 = rnorm(10))
dad2 = data.frame(var3 = letters[1:4],
var4 = rnorm(4))
l2 = list(s1 = dad1,
s2 = dad2,
s3 = 1:10,
s4 = matrix(1:12,
nr = 3,
nc = 4))
# Indexando listas
l1[[1]]
## [1] 2 6 8
## [1] 3
## [1] 8
## var3 var4
## 1 a 0.9642239
## 2 b -1.4082266
## 3 c -0.5658191
## 4 d 0.2039330
## var3 var4
## 1 a 0.9642239
## 2 b -1.4082266
## 3 c -0.5658191
## 4 d 0.2039330
## [1] "a" "b" "c" "d"
## [1] 0.9642239 -1.4082266 -0.5658191 0.2039330
# Nomeando uma lista
names(l1) = c('A','B','C')