Categories:
Cloud (204)
Entertainment (11)
Facebook (43)
General (50)
Life (31)
Programming (64)
Technology (430)
Testing (4)
Tools (488)
Twitter (5)
Wearable (26)
Web Design (44)
Collections:
Other Resources:
Data Structure - List
What is data structure "List"?
✍: FYIcenter.com
List is a special vector whose members are all lists.
1. Create a list object with the list() function -
> w = list( c(1,2,3), c("Apple", "Banana", "Orange"))
> w
[[1]]
[1] 1 2 3
[[2]]
[1] "Apple" "Banana" "Orange"
> is.list(w)
[1] TRUE
> is.vector(w)
[1] TRUE
2. Get vector length and members - Remember that member indexes start from 1.
> w = list( c(1,2,3), c("Apple", "Banana", "Orange"))
> length(w)
[1] 2
> w[2]
[[1]]
[1] "Apple" "Banana" "Orange"
> typeof(w[2])
[1] "list"
> length(w[2])
[1] 1
Since single square bracket [] only creates a sub-set of the vector, you need to use double square bracket [[]] access a list component.
> w = list( c(1,2,3), c("Apple", "Banana", "Orange"))
> w[2]
[[1]]
[1] "Apple" "Banana" "Orange"
> typeof(w[2])
[1] "list"
> w[[2]]
[1] "Apple" "Banana" "Orange"
> typeof(w[[2]])
[1] "character"
> w[[2]][2]
[1] "Banana"
So if "w" is a list, w[2] is still a sub-list with only the second component in it. w[[2]] is a vector and refers to the second component. w[[2]][2] now is a sub-vector with only the second value of the second component.
2023-06-11, 1073🔥, 0💬
Popular Posts:
Where to find answers to frequently asked questions about Fitbit devices? I want to understand more ...
How to install Mozilla Firefox 2.0 add-on: FireFTP? FireFTP is a Mozilla Firefox 2 add-on that provi...
How to create a new WeChat account with my Facebook account? Creating a new WeChat account with a Fa...
Why I am getting the "FTP over TLS is not enabled, users cannot securely log in" waring on my FileZi...
How to fix the Microphone Permissions error with making a call with Messenger in iPhone? If your Mic...