[R] minimum from matrix
dimitris.rizopoulos at med.kuleuven.be
Tue May 8 14:06:31 CEST 2007
apply(a, 2, function(x) min(x[x > 0]))
I hope it helps.
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
----- Original Message -----
From: <oarabile at stams.strath.ac.uk>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, May 08, 2007 10:50 AM
Subject: [R] minimum from matrix
> I have a very large matrix with columns that have some of their
> entries as zero
> A small example if a=
> [,1] [,2] [,3] [,4]
> [,1] 0 2 0 0
> [,2] 1 3 0 3
> [,3] 2 0 3 5
> [,4] 0 4 0 0
> and what to get the minimum number from each column but that number
> should not be zero. If I use apply (a,2,min) I will get a vector of
> zeros as the minimum but what I want it for example from column 1 I
> should get 1 i.e for all the matrix I should get a vector (1,2,3,3).
> wonder if someone can give an idea on how to go about it.
> thanks in advance for your help.
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help