Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
2列のマトリックスをマルチマップまたはリストのリストに変換する方法があるかどうか疑問に思っています。
マトリックスの最初の列は ID で (エントリが重複している可能性があります)、2 番目の列は何らかの値です。
たとえば、マトリックスに従う必要がある場合
m <- matrix(c(1,2,1,3,2,4), c(3,2))
次のリストに変換したいと思います
[[1]] 3,4 [[2]] 2
基本関数を使用すると、次のようなことができます。
tapply(m[,2], m[,1], `[`) # outputs an array by(m, m[,1], function(m) m[,2]) # outputs a by object, which is a list
使用できますplyr:
plyr
dlply(m, 1, function(m) m[,2]) # outputs a list dlply(m, 1, `[`, 2) # another way to do it...