n,LAUSANNE,Applied Mathematics
> Cc: r-help@r-project.org
> Subject: Re: [R] Replacing values in a data.frame/matrix
>
> how about:
>
> m <- matrix(c(1,2,3,2,1,3,3,1,2), ncol = 3, byrow = TRUE)
> perm <- c(1, 3, 2)
>
> out <- perm[m]
> dim(out) <- dim(m)
how about:
m <- matrix(c(1,2,3,2,1,3,3,1,2), ncol = 3, byrow = TRUE)
perm <- c(1, 3, 2)
out <- perm[m]
dim(out) <- dim(m)
out
I hope it helps.
Best,
Dimitris
On 3/8/2011 4:05 PM, Thaler, Thorn, LAUSANNE, Applied Mathematics wrote:
Hi all,
Suppose we have the following matrix
m<- matrix(c
Hi all,
Suppose we have the following matrix
m <- matrix(c(1,2,3,2,1,3,3,1,2), ncol = 3, byrow=T)
where in each row each number occurs only once.
I'd like to define a permutation, e.g. 1 -> 2, 2 -> 1, 3 -> 3 and apply
it to the matrix. Thus, the following matrix should result:
m.perm <- matrix
3 matches
Mail list logo