生成具有 "int" 结构的列表的语句?

Statement that produces list with "int" structure?

我正在熟悉 Jonathan Chang 和合著者的 lda R 包,准备自己进行类似的分析。我查看了内置cora.documentscora.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

其中没有作为 cora.cites 数据列出的 int 和维度 [,] 信息。

如何生成列表格式的数据,其结构类似于 lda 包的示例数据?

大致如下:

x<-list(integer(5),integer(5))
str(x)
# List of 2
# $ : int [1:5] 0 0 0 0 0
# $ : int [1:5] 0 0 0 0 0

如果您观察自己所做的,您创建了 lists 并将它们包含在 list 中。因此,您获得了列表作为 my_list 的元素。但是如果你检查 cora.sites 结构,元素是 integer 类型的 vectors。因此,您应该在 list 函数中传递整数向量。