[英]building list of vectors in R
I want to define a list of vectors. 我想定义一个向量列表。 The vector length is 4 and the length of list is N.
向量长度为4,列表长度为N.
I am trying 我在尝试
list A=as.list(rep(c("","","",""),length=N)
but I am getting output 但我得到输出
[[1]]
[1] ""
[[2]]
[1] ""
[[3]]
[1] ""
But I need the output as 但我需要输出为
[[1]]
[1] "" "" "" ""
[[2]]
[1] "" "" "" ""
[[3]]
[1] "" "" "" ""
How could this be done? 怎么可以这样做?
Thanks 谢谢
N<-10
lapply(1:N,function(x)rep(c("","","",""),N))
actually if you're not repeating N times (ie all items the same), you probably need: 实际上如果你不重复N次(即所有项目都相同),你可能需要:
lapply(1:N,function(x)c("","","",""))
This is similar to Troy's, but different enough that I think it's worth posting: 这类似于特洛伊的,但不同的我认为值得张贴:
replicate(N, character(4), s=F)
With N==3
: N==3
:
[[1]]
[1] "" "" "" ""
[[2]]
[1] "" "" "" ""
[[3]]
[1] "" "" "" ""
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.