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
Hi,You could do:
m1 <- as.matrix(read.table(text="3 0.9 1
5 0.5 0.7
7 0.1 0.3",sep="",header=FALSE))
dimnames(m1) <- NULL
d2 <- data.frame(V1=1:10)
d1 <- as.data.frame(m1)
library(zoo)
res <- na.locf(merge(d1,d2,all=TRUE))
res[is.na(res)] <- 1
res
#or
vec1 <- 1:10
indx <- vec1[!vec1 %in% m1[,1
4 matches
Mail list logo