1
ich so,die Hierarchie einer Liste in R
haben Liste ändernmyList <- lapply(unique(diamonds$cut), function(x){
lst <- lapply(unique(diamonds$color), function(y){
dta <- diamonds[diamonds$cut == x & diamonds$color == y, ]
lm(price ~ carat, data = dta)
})
names(lst) <- unique(diamonds$color)
return(lst)
})
names(myList) <- unique(diamonds$cut)
Die Struktur ist,
> str(myList, max.level=2)
List of 5
$ Ideal :List of 7
..$ E:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ I:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ J:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ H:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ F:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ G:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ D:List of 12
.. ..- attr(*, "class")= chr "lm"
$ Premium :List of 7
..$ E:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ I:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ J:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ H:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ F:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ G:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ D:List of 12
.. ..- attr(*, "class")= chr "lm"
$ Good :List of 7
..$ E:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ I:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ J:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ H:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ F:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ G:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ D:List of 12
.. ..- attr(*, "class")= chr "lm"
$ Very Good:List of 7
..$ E:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ I:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ J:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ H:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ F:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ G:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ D:List of 12
.. ..- attr(*, "class")= chr "lm"
$ Fair :List of 7
..$ E:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ I:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ J:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ H:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ F:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ G:List of 12
.. ..- attr(*, "class")= chr "lm"
..$ D:List of 12
.. ..- attr(*, "class")= chr "lm"
Ich möchte dies nach myList
mit so restrukturieren, dass jeder color
Willen kommt vor . Ich kann den Code, der myList
erstellt, nicht ändern. Ich muss es tun, nachdem myList
generiert wird. Einige helfen plz.
ich die Lösung aus einer ähnlichen Frage bei http://stackoverflow.com gefunden/questions/34643746/how-can-i-reshape-a-listen-of-list-from-wide-to-long, vielen Dank, das wird mir jetzt helfen – TheRimalaya