[R] Subset of Data
arun
smartpink111 at yahoo.com
Wed Dec 12 21:59:47 CET 2012
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.
________________________________
From: farnoosh sheikhi <farnoosh_81 at yahoo.com>
To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com>
Cc: "r-help at R-project.org" <r-help at 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
More information about the R-help
mailing list