[R] cbind and rbind

Andy Bunn abunn at whrc.org
Tue Aug 23 02:33:21 CEST 2005


Like this?

 x <- cbind(rnorm(10), rnorm(10))
# add row total
 x <- cbind(x, rowSums(x))
# add col sums
 x <- rbind(x, colSums(x))

The KEY to posting to r-help is writing a small example that helpers can
reproduce. When I write one, I often find the answer myself. I often don't
and get eviscerated by some R-guru, but that's part of the fun of it all!

I hope that helps, Andy


> -----Original Message-----
> From: Tony Evans [mailto:tonyevans at esat.net.au]
> Sent: Monday, August 22, 2005 8:03 PM
> To: Andy Bunn
> Subject: Re: [R] cbind and rbind
>
>
> Sorry, I did read the guide but am very new to this.
>
> I have created a table and have made totals of rows and columns using
> apply() I now want to add these totals to the table.
> I have been able to add one OR the other using cbind and rbind
> but have not
> been able to find a code to add them both.
>
> I hope this is better information.
>
> Tony Evans
> Australia
>
> ----- Original Message -----
> From: "Andy Bunn" <abunn at whrc.org>
> To: " Tony Evans" <tonyevans at esat.net.au>
> Sent: Tuesday, August 23, 2005 10:02 AM
> Subject: RE: [R] cbind and rbind
>
>
> > Try reading the posting guide and give a small example of what
> you want to
> > try and do...then we can help better.
> >
> > x <- rnorm(10)
> > y <- rnorm(10)
> > z <- cbind(x,y)
> > w <- rbind(z,rnorm(2))
> >
> >
> > -Andy
> >
> >
>
>




More information about the R-help mailing list