Re: [R] how to delete some columns from a matrix based on some other indicator variable

2006-09-24 Thread Ritwik Sinha
Hi, The problem might be mode of the vector "r". Try this D[,as.character(r)=="1"] But I am not sure that is the problem. Sometimes "factors" tend to complicate things. Look for "factor" in the R FAQ page. Ritwik. On 9/20/06, David Barron <[EMAIL PROTECTED]> wrote: > You don't need a loop. Yo

Re: [R] how to delete some columns from a matrix based on some other indicator variable

2006-09-20 Thread David Barron
You don't need a loop. You could try > r <- c(0,0,1,1) > matD <- matrix(1:12,nrow=3) > matD [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 > matD[,r==1] > matD[,r==1] [,1] [,2] [1,]7 10 [2,]8 11 [3,]9 12 On 20/09/06, Y

[R] how to delete some columns from a matrix based on some other indicator variable

2006-09-20 Thread Ya-Hsiu Chuang
Hello, I am not very familiar with R and need help in deleting a few columns in a matrix. Suppose I have a indicator variable called r and it's defined as r = (0, 0, 1, 1). A matrix D is a 3X4 matrix. If I want a new matrix which contains only the columns of D corresponding to the elements of