Select variables from a list of objects of the same type
selectFromList(x, select)
A list of objects of the same type.
A character vector of names of variables to select.
x <- list(
a = list(name = "John", age = 25, gender = "M"),
b = list(name = "Mary", age = 24, gender = "F")
)
selectFromList(x, c("name", "age"))
#> $a
#> $a$name
#> [1] "John"
#>
#> $a$age
#> [1] 25
#>
#>
#> $b
#> $b$name
#> [1] "Mary"
#>
#> $b$age
#> [1] 24
#>
#>
# $a
# $a$name
# [1] "John"
#
# $a$age
# [1] 25
#
#
# $b
# $b$name
# [1] "Mary"
#
# $b$age
# [1] 24