[R] cbind, row names

K. Elo maillists at nic.fi
Fri Jan 29 12:24:40 CET 2010


Hi!

29.01.2010 12:49, soeren.vogel at eawag.ch wrote:
> Hello,
> 
> I read the help as well as the examples, but I can not figure out why
> the following code does not produce the *given* row names, "x" and "y":
> 
> x <- 1:20
> y <- 21:40
> rbind(
>   x=cbind(N=length(x), M=mean(x), SD=sd(x)),
>   y=cbind(N=length(y), M=mean(y), SD=sd(y))
> )
> 

Maybe because the cbinds in your code produce matrices:

is.matrix(cbind("N"=length(x), "M"=mean(x), "SD"=sd(x)))
[1] TRUE

Quote ?rbind:
"For cbind (rbind) the column (row) names are taken from the colnames
(rownames) of the arguments if these are matrix-like."

HTH,
Kimmo



More information about the R-help mailing list