[R] stuff I used to do in Matlab

Ben Bolker ben at zoo.ufl.edu
Fri Sep 14 05:16:21 CEST 2001


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



More information about the R-help mailing list