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. How can I accomplish that? Thanks alot. -MY
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
Dear Minghua Yao, Commands of the form AA[, i] <- A do indeed work, although the number of elements in the i-th row of AA has to be a multiple of the number of elements in A. Perhaps you can specify in more detail what it is that you want to do and the nature of the error that you encountered. I hope that this helps, John At 10:00 AM 4/21/2003 -0500, 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. > >How can I accomplish that? > >Thanks alot. > >-MY >____________________________ John Fox Department of Sociology McMaster University email: jfox at mcmaster.ca web: http://www.socsci.mcmaster.ca/jfox