假设您要将矩阵转换为列表,其中列表的每个元素都包含一列.list()或者as.list()显然不起作用,直到现在我使用hack使用以下行为tapply:
x <- matrix(1:10,ncol=2)
tapply(x,rep(1:ncol(x),each=nrow(x)),function(i)i)
Run Code Online (Sandbox Code Playgroud)
我对此并不完全满意.谁知道我忽略了一种更清洁的方法?
(为了使列表填充行,代码显然可以更改为:
tapply(x,rep(1:nrow(x),ncol(x)),function(i)i)
Run Code Online (Sandbox Code Playgroud)
)