[R] Extracting part of an array

Achim Zeileis zeileis at ci.tuwien.ac.at
Tue Jun 18 16:26:14 CEST 2002


Poizot Emmanuel wrote:
> 
> Hi,
> I've got a trivial question ,but as a newby, I'm stuk.
> I've got an array of dim 160,4. I want to extract the values of the first
> column based on a condition of values in the second column and affect the
> result to a variable.

If I understand you correctly you want something like this:

R> dummy <- matrix(rnorm(160*4), ncol = 4)
R> dim(dummy)
[1] 160   4
R> result <- dummy[(dummy[,2] > 2), 1]
R> result
[1] 1.1762235 0.3720527

Hope that helps
Z


> E.P.
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list