Thank you very much, Marc and Bert - this is great!
On Tue, Dec 22, 2015 at 7:14 PM, Bert Gunter wrote:
> ... Perhaps worth noting is that the row indices can be created
> directly without row():
>
> result[cbind(rep.int(seq_len(6),5), as.vector(x))] <- 1
>
> but the downside is that you have to
... Perhaps worth noting is that the row indices can be created
directly without row():
result[cbind(rep.int(seq_len(6),5), as.vector(x))] <- 1
but the downside is that you have to know that a matrix is a vector
"stored" in column major order. I find this arcane detail quite handy,
though.
Cheer
> On Dec 22, 2015, at 4:42 PM, Dimitri Liakhovitski
> wrote:
>
> # I have a matrix x:
>
> k <- 20
> N <- 5
> set.seed(123)
> x <- matrix(c(sample(1:k, N, replace = F),
> sample(1:k, N, replace = F),
> sample(1:k, N, replace = F),
> sample(1:k, N, replace
# I have a matrix x:
k <- 20
N <- 5
set.seed(123)
x <- matrix(c(sample(1:k, N, replace = F),
sample(1:k, N, replace = F),
sample(1:k, N, replace = F),
sample(1:k, N, replace = F),
sample(1:k, N, replace = F),
sample(1:k, N, repl
4 matches
Mail list logo