In my simulation I need a vector that looks like:
vec = NULL NULL NULL NULL 2 2 2 2 4 4 4 4
However, in R when I use rep(NULL, 4)
it returns nothing. For example,
vec.all = c(rep(NULL, 4), rep(2, 4), rep(4, 4))
vec.all
2 2 2 2 4 4 4 4
Is there a way to repeat NULL
several times in R? Thanks!
NULL
has no length:
> length(NULL)
[1] 0
So you can't really insert it into a vector. You can either have NA
in you vectors or have a list with NULL
items.
vec.all = c(rep(NA, 4), rep(2, 4), rep(4, 4))
list.all = c(rep(list(NULL), 4), rep(list(2), 4), rep(list(4), 4))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With