[R] extraction - subsets

Chuck Cleland ccleland at optonline.net
Sat Mar 18 19:03:53 CET 2006


matrixX[vectorY %in% subsample,]

?"%in%"

Roberto Furlan wrote:
> 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
> 
> --
> ----------------------------------------
> La mia Cartella di Posta in Arrivo è protetta da SPAMfighter
> 259 messaggi contenenti spam sono stati bloccati con successo.
> Scarica gratuitamente SPAMfighter!
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894




More information about the R-help mailing list