 Hi,

this should work fine:
subset <- c(2,3)
for (n in subset) {
cat(n,":",matrixX[as.integer(vectorY[row(vectorY)==n]),])
}

Good luck

Bart

Original message:


From: Roberto Furlan <roberto.furlan_at_gmail.com> 
Date: Sun 19 Mar 2006 - 04:47:47 EST


Hi everybody, 
let us assume i have the following matrixX and vectorY 

matrixX <- runif(100) 
dim(matrixX) <- c(10,10) 
vectorY <- as.matrix(as.character(seq(1,10))) 

if I define: 
subsample<-c("2") 

i can extract the rows from matriX based on the elements in vectorY which are listed in subsample 
matrixX[vectorY==subsample] 

if I define subsample with more than 1 element, such as: subsample=c("2", "3") 

how can i extract the rows from matriX based on the elements in vectorY which are listed in subsample? 

many thanks 

Roberto Furlan 
University of Turin 

	[[alternative HTML version deleted]]


