I come from a Python background but have to learn R for a job, and I am confused about lists.
I understand named lists can be (roughly) equivalent to Python dictionaries, and I can look up elements either by index using example_list[[1]]
or example_list$name
if I know the name of the key.
example_list <- list(a=1, b=3, c="d", f=list(1:4))
example_list$c #"d"
example_list$f #[[1]] [1] 1 2 3 4
example_list$f[[1]] # [1] 1 2 3 4
example_list[["f"]][[1]][[1]] # [1] 1
When I was playing around, I noticed to get "1" from f
, I had to use [[1]]
twice? I was expecting f
to be [1, 2, 3, 4]
but it seems to be [[1,2,3,4]]
, am I understanding this correctly?
c()
is completely unnecessary.f=1:4
would be fine.