[R] Matrix to Vector

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jul 1 18:48:51 CEST 2003


On Tue, 1 Jul 2003, Arun Horne wrote:

> I have a matrix of values that I want to convert to a vector, but remove
> certain entries in the matrix first, i.e. in the vector I want every value
> in the matrix that is greater than 1000. I would also like to find out how
> many values are excluded in the transition from matrix to vector. Could
> someone tell me how this can be done?

start with matrix A, and treat it like a vector (which it is)

vec <- A[A > 1000]  (reads down columns, BTW)
excluded <- sum(!(A > 1000))


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list