Re: [R] extract columns of a matrix/data frame

2007-07-31 Thread Marc Schwartz
On Tue, 2007-07-31 at 11:47 -0700, yuvika wrote: > Hello, > > Thanks for the immediate help. However, I have a question for you. > let's say the matrix looks like this > > name a1 a2 b1 b2 c1 c2 > 04 2 7 8 1 2 > 03 6 9 2

Re: [R] extract columns of a matrix/data frame

2007-07-31 Thread Marc Schwartz
On Tue, 2007-07-31 at 10:35 -0700, yuvika wrote: > Hello all, > > I have a matrix whose column names look like > > a1 a2 b1 b2 b3 c1 c2 > 1 23713 2 > 4 67814 3 > > Now, I can have any number of a's. not just two as shown above and >

Re: [R] extract columns of a matrix/data frame

2007-07-31 Thread Chuck Cleland
yuvika wrote: > Hello all, > > I have a matrix whose column names look like > > a1 a2 b1 b2 b3 c1 c2 > 1 23713 2 > 4 67814 3 > > Now, I can have any number of a's. not just two as shown above and same > goes for b's and c's. I nee

Re: [R] extract columns of a matrix/data frame

2007-07-31 Thread Kyle.
Sorry. There was a mistake in my previous code. Please disregard it and use the following: > r1=c(1,2,3,7,1,3,2) > r2=c(4,5,7,8,1,4,3) > test=matrix(c(r1,r2),nrow=2,ncol=7,byrow=TRUE) > colnames(test)<-c("a1","a2","b1","b2","b3","c1","c2") > test [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1

Re: [R] extract columns of a matrix/data frame

2007-07-31 Thread Kyle.
You can use the grep function to obtain the column indices matching your specified criteria. For example, > r1<-c(1,2,3,7,1,3,2) > r2<-c(4,5,7,8,1,4,3) > test<-matrix(c(r1,r2),byrow=TRUE) > colnames(test)<-c("a1","a2","b1","b2","b3","c1","c2") > test a1 a2 b1 b2 b3 c1 c2 [1,] 1 2