Suppose I have a list like this :
m <- list('a' = list('b' = c(1, 2), 'c' = 3, 'b1' = 4))
I want to get the names of m
and maintain the levels also.
If I do
names(unlist(m))
It gives output
"a.b1" "a.b2" "a.c" "a.b1"
But I want only names like
"a.b" "a.c" "a.b1"
How to get that ?
Also unlist()
is a costly operation for big nested lists. Is there any way to do it without unlist()
and in a faster way ?
Example 2 :
p = list( 'a' = list( 'z' = c( 1, 2 ), 'g' = list( 'i' = 2, 'j' = 3 ) ), 'd' = list( 'k' = c( 4, 5 ) ) )
Example 3 :
p = list( 'a' = list( 'z' = c( 1, 2 ), 'g' = list( 2, 3 ) ), 'd' = list( 'k' = c( 4, 5 ) ) )
See Question&Answers more detail:os