How can i access list of list

You need to iterate through the list to operate on the element you want.

You can also select to filter the list. Here are two ways:

sample <- list(
  Fold01 = list(Accuracy = 96.4, 
                Sensitivity = 83.3,
                Specificity = 100),
  Fold02 = list(Accuracy = 100, 
                Sensitivity = 100,
                Specificity = 100)
)

# base R solution
sapply(sample, function(x) x$Accuracy)
#> Fold01 Fold02 
#>   96.4  100.0

# tidyverse equivalent with purrr (safer)
library(purrr)
# a list 
sample %>% map("Accuracy")
#> $Fold01
#> [1] 96.4
#> 
#> $Fold02
#> [1] 100
# a vector of numeric
sample %>% map_dbl("Accuracy")
#> Fold01 Fold02 
#>   96.4  100.0

Created on 2018-12-16 by the reprex package (v0.2.1)

For list manipulation, purrr is really a good tool! You should look into it.

1 Like