[R] Matrix: Problem with the code

2009-01-09 Thread Bhargab Chattopadhyay
Hi, Can any one please explain why the following code doesn't work? Or can anyone suggest an alternative. Suppose   x-c(23,67,2,87,9,63,8,2,35,6,91,41,22,3)    mat-0;    for(j in 1:length(x))    {      for(i in 1:p)      mat[i,j]-x[j]^i;    }   

Re: [R] Matrix: Problem with the code

2009-01-09 Thread Sarah Goslee
Well, mat doesn't have any dimensions / isn't a matrix, and we don't know what p is supposed to be. But leaving aside those little details, do you perhaps want something like this: x-c(23,67,2,87,9,63,8,2,35,6,91,41,22,3) p - 5 mat- matrix(0, nrow=p, ncol=length(x)) for(j

Re: [R] Matrix: Problem with the code

2009-01-09 Thread Charlotte Wickham
One of those more elegant ways: outer(x, 1:p, ^) Charlotte On Fri, Jan 9, 2009 at 4:24 PM, Sarah Goslee sarah.gos...@gmail.com wrote: Well, mat doesn't have any dimensions / isn't a matrix, and we don't know what p is supposed to be. But leaving aside those little details, do you perhaps want

Re: [R] Matrix: Problem with the code

2009-01-09 Thread markleeds
Charlotte: I ran your code because I wasn't clear on it and your way would cause more matrices than the person requested. So I think the code below it, although not too short, does what the person asked. Thanks though because I understand outer better now. temp - matrix(c(1,2,3,4,5,6),ncol=2)

Re: [R] Matrix: Problem with the code

2009-01-09 Thread Kingsford Jones
On Fri, Jan 9, 2009 at 6:36 PM, markle...@verizon.net wrote: Charlotte: I ran your code because I wasn't clear on it and your way would cause more matrices than the person requested. Bhargab gave us x-c(23,67,2,87,9,63,8,2,35,6,91,41,22,3) and said: I want to have a matrix with p

Re: [R] Matrix: Problem with the code

2009-01-09 Thread markleeds
Thanks Kingsford. I thought the column power was supposed to be just for that column but you're probably correct. English has its oddities because if one reads the actual sentence the person wrote it's still not clear, atleast to me. Actually I want to have a matrix with p columns such that