Thank you so much. It worked very well:) Best,Farnoosh Sheikhi
________________________________ Cc: R help <r-help@r-project.org> Sent: Wednesday, December 12, 2012 12:59 PM Subject: Re: Subset of Data Hi Farnoosh, Try this: set.seed(151) mat1<-matrix(sample(1:400,100,replace=TRUE),ncol=20) set.seed(15) colnames(mat1)<-paste(sample(c("proc","Lab","other"),20,replace=TRUE),sample(1:45,20,replace=FALSE),sep="") mat1[,grepl("proc|Lab",colnames(mat1))] # Lab37 proc35 Lab3 Lab24 proc6 proc36 Lab9 Lab17 Lab32 proc34 #[1,] 192 246 241 126 374 122 281 116 215 4 #[2,] 347 182 237 393 300 49 125 90 245 148 #[3,] 312 329 144 285 224 110 378 329 275 79 #[4,] 216 139 300 230 249 206 231 357 188 87 #[5,] 177 383 102 211 26 283 20 351 392 286 #if you want columns not "Lab" or "proc" mat1[,!grepl("proc|Lab",colnames(mat1))] A.K. ________________________________ Cc: "r-help@R-project.org" <r-help@R-project.org> Sent: Wednesday, December 12, 2012 3:39 PM Subject: Subset of Data Hi Arun, I have a question about choosing a subset of data. I have a matrix of 5000 in 3500. I want to choose specific variables such as proc1 to proc1000 and Lab1 to Lab1600 and put it into a new matrix to run some correlation analysis. Since I have 3500 variables, I don't know from what column my lab or procedures start. I really appreciate your help. Thanks. Best,Farnoosh Sheikhi [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.