Re: [R] Help on a matrix task

From: Adrian DUSA <adi_at_roda.ro>
Date: Fri 09 Dec 2005 - 06:20:11 EST

On Tuesday 06 December 2005 14:41, JeeBee wrote:
> [...]
> N = 4
>
> input_numbers = seq((2^N)-1, 0, -1)
> # convert to binary matrix
> input_mat = NULL
> for(i in seq(N-1,0,-1)) {
> new_col = input_numbers %% 2
> input_mat = cbind(new_col, input_mat)
> input_numbers = (input_numbers - new_col) / 2
> }
> colnames(input_mat) = NULL

A little late, but wouldn't be more simple to create input_mat with: N <- 4
input_mat <- matrix(NA, ncol=N, nrow=2^N) for (i in 1:N) input_mat[,i] <- c(rep(0, 2^(N - i)), rep(1, 2^(N - i)))

HTH,
Adrian

-- 
Adrian DUSA
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
          +40 21 3120210 / int.101

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Dec 09 06:33:09 2005

This archive was generated by hypermail 2.1.8 : Fri 09 Dec 2005 - 09:31:34 EST