0
我想定義一個向量列表。矢量長度爲4和列表的長度爲N.在R中構建向量列表
我想
,但我得到的輸出
[[1]]
[1] ""
[[2]]
[1] ""
[[3]]
[1] ""
但我需要的輸出作爲
[[1]]
[1] "" "" "" ""
[[2]]
[1] "" "" "" ""
[[3]]
[1] "" "" "" ""
這怎麼辦?
感謝
我想定義一個向量列表。矢量長度爲4和列表的長度爲N.在R中構建向量列表
我想
,但我得到的輸出
[[1]]
[1] ""
[[2]]
[1] ""
[[3]]
[1] ""
但我需要的輸出作爲
[[1]]
[1] "" "" "" ""
[[2]]
[1] "" "" "" ""
[[3]]
[1] "" "" "" ""
這怎麼辦?
感謝
N<-10
lapply(1:N,function(x)rep(c("","","",""),N))
實際上,如果你不重複N次(即所有項目一樣),你可能需要:
lapply(1:N,function(x)c("","","",""))
這類似於特洛伊的,但不同的不夠,我認爲這是值得發帖:
replicate(N, character(4), s=F)
隨着N==3
:
[[1]]
[1] "" "" "" ""
[[2]]
[1] "" "" "" ""
[[3]]
[1] "" "" "" ""