[R] Selecting out certain values from a MATRIX

Phil Spector spector at stat.Berkeley.EDU
Tue Apr 4 21:19:33 CEST 2006


myMatrix[myVector < .5,]
or
subset(myMatrix,myVector< .5)
                                        - Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Tue, 4 Apr 2006, mark salsburg wrote:

> I have two objects, one matrix and one vector.
>
> I want to use my vector to subset certain values out of my matrix.
>
> For example:
>
> I want to tell R, to select out all rows in myMatrix into a new myMatrix2 IF
> that corresponding row is less than a 0.5 in myVector.
>
> So:
>
> myMatrix = a matrix of 8000 by 20
> myVector = vector of 8000
>
> myMatrix2 = a matrix of < 8000 by 20 (based on selection criteria in
> myVector)
>
> I hope this makes sense..
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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
>




More information about the R-help mailing list