Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.LNX.4.30.0109132314510.12415-100000@bolker.zoo.ufl.edu>
Date: 2001-09-14T03:16:21Z
From: Ben Bolker
Subject: stuff I used to do in Matlab
In-Reply-To: <Pine.GSO.4.20.0109132113260.25232-100000@jade.saintmarys.edu>

On Thu, 13 Sep 2001, David A Richmond wrote:

> Hi,
> 	I'm new to R, and trying to map stuff I knew how to do in Matlab
> to R. For instances, in matlab, sum(x) gave the column sums of
> matrix(/vector) x. In R it just gives the sum of all the elements,
> regardless of their form (vector or matrix). Is there a simple way to
> return a vector of column sums for a matrix?

  apply(x,2,sum)   gives column sums
  apply(x,1,sum)   gives row sums


> Also, in Matlab binary
> operators exist for concatenating a matrix onto the end or the bottom of
> another matrix (i.e. horiz or vertically) but no such operators seem to
> exist for R. is there an easy way to concatenate matrices? (I have found a
> way which involves several steps, first creating a new matrix of zeros
> with dimensions based on the dims of the old ones, and then inserting the
> contents of the old matrices into the new one, but this seems very
> cumbersome, esp. since I'm used to being able to do it with something like
> c = [a,b]. Thanks for entertaining my newbie questions

  cbind(x,y)  concatenates matrices by column
  rbind(x,y)  concatenates matrices by row


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._