【发布时间】:2018-03-04 15:29:23
【问题描述】:
我正在熟悉 Jonathan Chang 和合著者的lda R 包,以准备对自己进行类似的分析。我检查了内置的cora.documents和cora.cites数据的结构,它们是以列表格式存储的,但是像这样
library(lda)
str(cora.cites)
List of 2410
$ : int [1:2] 484 389
$ : int(0)
$ : int(0)
$ : int [1:3] 177 416 533
$ : int 153
$ : int(0)
$ : int(0)
$ : int(0)
$ : int(0)
$ : int(0)
$ : int(0)
$ : int 139
$ : int 433
$ : int [1:16] 233 391 350 208 484 666 218 630 28 656 ...
$ : int [1:8] 210 624 229 136 356 228 289 73
$ : int(0)
在哪里
class(cora.cites)
[1] "list"
class(cora.cites[1])
[1] "list"
但如果我要构建类似结构的数据,例如,
list1 <- list(484, 389)
list2 <- list(0)
list3 <- list(0)
list4 <- list(177, 416, 533)
my_list <- list(list1, list2, list3, list4)
原来是这样
str(my_list)
List of 4
$ :List of 2
..$ : num 484
..$ : num 389
$ :List of 1
..$ : num 0
$ :List of 1
..$ : num 0
$ :List of 3
..$ : num 177
..$ : num 416
..$ : num 533
其中不附带int 和维度[,] 信息列为cora.cites 数据。
如何生成类似于lda 包的示例数据结构的列表格式数据?
【问题讨论】: