Results transposed with R apply [duplicate]

泪湿孤枕 提交于 2019-11-28 02:09:55

Combining the results of the individual apply steps is somewhat arbitrary. On what basis was your expectation different? The behaviour you see is how the documentation describes it:

If each call to ‘FUN’ returns a vector of length ‘n’, then ‘apply’ returns an array of dimension ‘c(n, dim(X)[MARGIN])’ if ‘n > 1’.

Note that you can easily perform the transpose afterwards:

> t(applied)
          [,1]      [,2]      [,3]      [,4]
[1,] 0.1000000 0.2000000 0.3000000 0.4000000
[2,] 0.1428571 0.2142857 0.2857143 0.3571429
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!