[R] trivial question about nested loops

dan roberts bro092 at yahoo.com
Thu Sep 2 16:26:31 CEST 2004


Hello,

It's a trivial question but I haven't found a solution in the
full reference manual. How can I make the code below run? Would
an array/matrix solution be faster? Please provide a short
example, if possible.

Thanks in advance,
dan

for (k in 1:5) 
	assign(paste("f",k,sep=""),vector(mode="complex",5))
for (k in 1:5) {
	for(j in 1:5) 
		f[k][[j]] <- sum(d$Y[k]*exp(-1i*j*d$X)) }
Error: Object "f" not found

(I want f[k] to become f1,...,f5; and d$Y[k] should be
d$Y1,...,d$Y5.)




More information about the R-help mailing list