[R] R: extracting elements in a matrix

Peter Wolf pwolf at wiwi.uni-bielefeld.de
Thu Sep 22 11:47:15 CEST 2005


... you can, for example

set.seed(13)
x<-matrix(rnorm(100),20,5)
lapply(split(x,col(x)),
       function(x){
         limit<-diff(quantile(x,c(.25,.75)))
         x[x>limit]
       })
output:
$"1"
[1] 1.775163 1.142526 1.229507 1.105144 1.396432
$"2"
[1] 1.836163
$"3"
[1] 1.590034 1.614479 1.408354 1.483691
$"4"
[1] 1.745427
$"5"
[1] 1.602120

Peter Wolf

Frank Schmid wrote:
>Dear R-users
> 
>For a given matrix of dimension, say (n,p), I'd like to extract for every
>column those elements that are bigger than twice the interquartile range of
>the corresponding column. 
> 
>Can I get these elements without using a loop?
> 
> 
>Thank you for your help
> 
> 
>Frank
> 
> 
> 
>
>		
>	
> 
>
>	[[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