[R] What is the matrix version of min()
Tong Wang
wangtong at usc.edu
Wed Sep 6 11:14:11 CEST 2006
Hi,
THANK YOU ALL for the prompt reply.
cheers.
----- Original Message -----
From: Robin Hankin <r.hankin at noc.soton.ac.uk>
Date: Wednesday, September 6, 2006 1:42 am
Subject: Re: [R] What is the matrix version of min()
To: Tong Wang <wangtong at usc.edu>
Cc: R help <r-help at stat.math.ethz.ch>
> Tong
>
> you need to use apply(). The second argument specifies whether
> you want to work with rows or columns. The point of this is that
> min() and max() operate on vectors and give a single value,
> and you want to "apply" this function to all rows or all columns:
>
> > a <- matrix(rnorm(30),5,6)
> > apply(a,2,max)
> [1] 2.6413241 0.9842076 1.7989560 0.6999855 2.0542201 0.1162821
> > apply(a,1,max)
> [1] 1.1771370 0.9811693 2.6413241 0.9842076 2.0542201
> >
>
> HTH
>
> rksh
>
>
> On 6 Sep 2006, at 09:37, Tong Wang wrote:
>
> > Hi,
> > Is there a function which operates on a matrix and return a
> > vector of min/max of each rol/col ?
> > say, X= 2, 1
> > 3, 4
> > min.col(X)=c(2,1)
> >
> > thanks a lot.
> >
> > tong
> >
> > ______________________________________________
> > 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
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
> tel 023-8059-7743
>
>
>
>
>
More information about the R-help
mailing list