Abdallah Atef
Abdallah Atef

Reputation: 671

Create long list in R

I want to create a list in R that has 81 elements each of which is a length 1 vector with the value value NA. I tried

list = list(rep(NA, 81))

But this create a list of 1 element of length 81. I also tried:

list = list(rep(list(NA),81))

But this returns a list of 81 elements which are nested lists not vectors. My desired output is something like this:

> list
[[1]]
[1] NA

[[2]]
[1] NA

[[3]]
[1] NA
.
.
.
[[81]]
[1] NA

Upvotes: 0

Views: 877

Answers (1)

Thraupidae
Thraupidae

Reputation: 675

You were close, try this line of code here

rep(list(NA),81)

Upvotes: 2

Related Questions