Been trying to resolve the following for a couple of hours now.
So I have a list, say:
Wyoming <- c("City1", "City2", "City3", ...)
Ontario <- c("City1", "City2", "City3", ...)
Florida <- c("City1", "City2", "City3", ...)
... # for all federated states
Mexico <- list(Sonora, Yucatan, Chiapas, Sinaloa)
Canada <- list(Alberta, Quebec, Ontario, Manitoba)
USA <- list(Wyoming, Colorado, NewHampshire, Florida)
ListOriginal <- list(USA, Canada, Mexico)
I'd like to remove the parent level (USA, Canada, Mexico) but keep the federated states, all of them in a single list. So it would appear like this:
$Wyoming
[1] "City1" "City2" "City3" ...
$Colorado
[1] "City1" "City2" "City3" ...
$Chiapas
[1] "City1" "City2" "City3" ...
#etc... for every federated state
With everything I have been trying so far, for instance when I use the following...
NorthAmericaFedStates <- sapply(ListOriginal, "[[", 1)
... the problem is that it will keep the top "parent", in this case the country name, and will show the cities directly, probably like this:
$Mexico
[1] "City1" "City2" "City3"
[2] "City1" "City2" "City3"
[3] "City1" "City2" "City3"
# etc
$Canada
[1] "City1" "City2" "City3"
[2] "City1" "City2" "City3"
[3] "City1" "City2" "City3"
# etc
I am able to choose what I want and show it in the console and save the result in a variable, but when I print the variable it will have the same problem as above.
ExactDataIWant <- function(x) {
Data <- x[1]
print(blabla)
}
ExactData <- lapply(OriginalList, ExactDataIWant)
This above shows me the data I want, (the state, then the cities), but when I type ExactData to print it in the console it gets me back to the start, with the country on top.
Any help please?