0

I want to define a list of vectors. The vector length is 4 and the length of list is 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

2 Answers 2

1
N<-10 lapply(1:N,function(x)rep(c("","","",""),N)) 

actually if you're not repeating N times (i.e. all items the same), you probably need:

lapply(1:N,function(x)c("","","","")) 
Sign up to request clarification or add additional context in comments.

Comments

1

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:

[[1]] [1] "" "" "" "" [[2]] [1] "" "" "" "" [[3]] [1] "" "" "" "" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.