[R] Matrix: Problem with the code
sarah.goslee at gmail.com
Sat Jan 10 01:24:08 CET 2009
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:
p <- 5
mat<- matrix(0, nrow=p, ncol=length(x))
for(j in 1:length(x))
for(i in 1:p)
Two notes: I didn't try it out, and if that's what you want rather
than a toy example
of a larger problem, there are more elegant ways to do it in R.
On Fri, Jan 9, 2009 at 6:42 PM, Bhargab Chattopadhyay
<bhargab_1 at yahoo.com> wrote:
> Can any one please explain why the following code doesn't work? Or can anyone suggest an alternative.
> for(j in 1:length(x))
> for(i in 1:p)
> Actually I want to have a matrix with p columns such that each column will have the elements of x^(column#).
> Thanks in advance.
More information about the R-help