Re: [R]

About this list Date view Thread view Subject view Author view Attachment view

From: Peter Dalgaard BSA (p.dalgaard@biostat.ku.dk)
Date: Tue 01 Apr 2003 - 00:56:54 EST


Message-id: <x2adfbfutl.fsf@biostat.ku.dk>

volkswirt@gmx.net writes:

> How can I remove all rows/collumns from a matrix that fulfill a certain
> condition? For instance: remove all negative elements from a [n,1]-matrix.
> I intended to write a function for this aim, but it does not work. Despite
> that it may help to get my point, when I ad it:
>
> kratek<-function(eine)
> {
> halt<-0
> for(index in 1:dim(eine)[1])
> {
> if(eine[(index-halt),1]<=0)
> {
> eine<-eine[-(index-halt),]
> halt<-halt+1
> }
> }
> eine
> }

Like this?

m <- matrix(rnorm(20),ncol=2)
m[6,1]<-NA
m[-which(m[,1]<=0),]

(Notice that this is not the same as m[m[,1]>0,] as soon as NA's are
involved).

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:11:33 EST