Suppose I have a numeric vector v
v <- 1:5
I want to
rep
v[1]
by v[1]
times.
v[2]
by v[2]
times... and so on....
所需的输出将是:
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
以下无效。有任何想法吗?
rep(v, each = function(x) v[x])
提前谢谢了。
Suppose I have a numeric vector v
v <- 1:5
I want to
rep
v[1]
by v[1]
times.
v[2]
by v[2]
times... and so on....
所需的输出将是:
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
以下无效。有任何想法吗?
rep(v, each = function(x) v[x])
提前谢谢了。
We can use
rep
on itselfIf we want to specify the argument, use
times
The
each
would not take anonymous function and it takes only a vector of length 1. According to?rep