amed12
December 12, 2018, 9:13am
1
how should i do to access list of list i have created
str(cv_results)
List of 10
$ Fold01:List of 3
..$ : Named num 96.4
.. ..- attr(*, "names")= chr "Accuracy"
..$ : Named num 83.3
.. ..- attr(*, "names")= chr "Sensitivity"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Specificity"
$ Fold02:List of 3
..$ : Named num 100
.. ..- attr(*, "names")= chr "Accuracy"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Sensitivity"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Specificity"
$ Fold03:List of 3
..$ : Named num 100
.. ..- attr(*, "names")= chr "Accuracy"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Sensitivity"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Specificity"
$ Fold04:List of 3
..$ : Named num 96.4
.. ..- attr(*, "names")= chr "Accuracy"
..$ : Named num 83.3
.. ..- attr(*, "names")= chr "Sensitivity"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Specificity"
$ Fold05:List of 3
..$ : Named num 100
.. ..- attr(*, "names")= chr "Accuracy"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Sensitivity"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Specificity"
$ Fold06:List of 3
..$ : Named num 96.4
.. ..- attr(*, "names")= chr "Accuracy"
..$ : Named num 83.3
.. ..- attr(*, "names")= chr "Sensitivity"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Specificity"
$ Fold07:List of 3
..$ : Named num 96.3
.. ..- attr(*, "names")= chr "Accuracy"
..$ : Named num 83.3
.. ..- attr(*, "names")= chr "Sensitivity"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Specificity"
$ Fold08:List of 3
..$ : Named num 100
.. ..- attr(*, "names")= chr "Accuracy"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Sensitivity"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Specificity"
$ Fold09:List of 3
..$ : Named num 100
.. ..- attr(*, "names")= chr "Accuracy"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Sensitivity"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Specificity"
$ Fold10:List of 3
..$ : Named num 100
.. ..- attr(*, "names")= chr "Accuracy"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Sensitivity"
..$ : Named num 100
.. ..- attr(*, "names")= chr "Specificity"
i want the output just "Accuracy" ... Thanks
Hi, can you start with providing a reprex? This would help a lot in solving your problem.
Why reprex?
Getting unstuck is hard. Your first step here is usually to create a reprex, or reproducible example. The goal of a reprex is to package your code, and information about your problem so that others can run it and feel your pain. Then, hopefully, folks can more easily provide a solution.
What's in a Reproducible Example?
Parts of a reproducible example:
background information - Describe what you are trying to do. What have you already done?
complete set up - include any library() calls and data to reproduce your issue.
data for a reprex: Here's a discussion on setting up data for a reprex
make it run - include the minimal code required to reproduce your error on the data…
In general, all things list can be either solved with *apply
functions (sapply
, for example) or with purrr::map_*
. In you case you should take a look at purrr::map_dbl
.
1 Like
cderv
December 16, 2018, 10:47am
3
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
cderv
December 22, 2018, 2:58pm
5
If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:
If your question has been answered, don't forget to mark the solution!
How do I mark a solution?
Find the reply you want to mark as the solution and look for the row of small gray icons at the bottom of that reply. Click the one that looks like a box with a checkmark in it:
[image]
Hovering over the mark solution button shows the label, "Select if this reply solves the problem". If you don't see the mark solution button, try clicking the three dots button ( ••• ) to expand the full set of options.
When a solution is chosen, the icon turns green and the hover label changes to: "Unselect if this reply no longer solves the problem". Success!
[solution_reply_author]
…
system
Closed
December 29, 2018, 2:58pm
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.