How to get the name of variables of the first level of a list?

Viewed 110

I have a list in R called myLst. This list contains different dataframes with the name:

myLst$'2014'$total
myLst$'2015'$total
myLst$'2016'$total
myLst$'2017'$total

How can I get the info of the first level of the list, such as ['2014', '2015', '2016', '2017']

1 Answers

We can use parse_number

readr::parse_number(names(myLst))
#[1] 2014 2015 2016 2017

data

myLst <- setNames(as.list(1:4), paste0("myLst$'", 2014:2017, "'$total"))
Related