R may have its own loigc but list()
did not give me what I expected.
l1 <- list(1,2)
$> l1
[[1]]
[1] 1
[[2]]
[1] 2
To retrieve the element, I need to use double-bracket, i.e.,
$> l1[[1]]
[1] 1
$> class(l1[[1]])
"numeric"
Single-bracket gives me, a sub-list (which is also a list object):
$> l1[1]
l1[[1]]
[1] 1
$> class(l1[1])
"list"
I am not saying this is wrong; this isn't what I expected because I was trying to create a 1-dimensional list whereas what I actually get is a nested list, a 2-dimensional object.
What is the logic behind this behaviour and how do we create an OO type list? i.e., a 1-dimensional data structure?
The behaviour I am expecting, with a 1 dimensional data structure, is:
$> l1[1]
[1] 1
$> l1[2]
[2] 2