[R] How to assigen column of matrix

Thomas Lumley tlumley at u.washington.edu
Mon Apr 21 17:25:50 CEST 2003


On Mon, 21 Apr 2003, Minghua Yao wrote:

>
> Hi,
>
> A simple question.
>
> I want to assign values to columns (or rows) of a matrix.
>
> It seems that
> AA[,i]<-A; # A is a vector or array;
> doesn't work.
>

It seems that it does work for me:
> AA<-matrix(1:4,2)
> AA
     [,1] [,2]
[1,]    1    3
[2,]    2    4
> A<-c(10,11)
> AA[,2]<-A
> AA
     [,1] [,2]
[1,]    1   10
[2,]    2   11

if that's what you were trying to do.  Note that command lines in R don't
end with a ;, but in this case it doesn't matter.

	-thomas



More information about the R-help mailing list