In the list, the first component has automatically endowed ``, why ? I think it should be $f instead of $`f`.
> list(f=c(1,2),h=c(1,2))
$`f`
[1] 1 2
$h
[1] 1 2
In the list, the first component has automatically endowed ``, why ? I think it should be $f instead of $`f`.
> list(f=c(1,2),h=c(1,2))
$`f`
[1] 1 2
$h
[1] 1 2
This will happen if you use numeric values as list elements names. This is done to clearly differentiate the list indices (e.g. list[1]
) from the list names (e.g. list$'1'
- wrong quotes du to formatting here).
In your example:
list <- list(f=c(1,2),h=c(1,2))
$f
[1] 1 2
$h
[1] 1 2
The elements f
and h
can be accessed through naming or indexing:
# Naming
list$f
[1] 1 2
# Indexing
list[1]
$f
[1] 1 2
# Indexing (alternative)
list[[1]]
[1] 1 2
On the other hand, if your list names have numbers they will be coerced as non-numeric values to avoid confusion:
list <- list("2"=c(1,2),h=c(1,2))
$`2`
[1] 1 2
$h
[1] 1 2
# Naming
list$`2`
[1] 1 2
# Indexing
list[1]
$`2`
[1] 1 2
# Indexing (alternative)
list[[1]]
[1] 1 2