Convert a vector of lists with uneven length to a matrix

流过昼夜 提交于 2019-12-01 08:53:54

I guess the 'data' should be a list instead of a vector, then the code would work

t(sapply(data, `length<-`, max(lengths(data))))

NOTE: lengths is a faster option (introduced in the recent R versions) that replaces sapply(data, length)

data

data = list(
  c(349, 364, 393, 356, 357, 394, 334, 394, 343, 365, 349),
  c(390, 336, 752, 377),
  c(670, 757, 405, 343, 1109, 350, 372),
  c(0, 0),
  numeric(0),
  c(1115, 394, 327, 356, 408, 329, 385, 357, 357))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!