Re: [R] Loop and function

2007-07-05 Thread jim holtman
Please show use the statements that you used. Did you put the 'str' inside the loop? It is hard to tell what is happening without reproducible code. On 7/5/07, livia <[EMAIL PROTECTED]> wrote: > > > I tried str(gpdlow(var[,i][var[,i]<(p[,i][[2]])) and it returns num [1:49] > -1.92 -1.69 -2.20 -1

Re: [R] Loop and function

2007-07-05 Thread livia
I tried str(gpdlow(var[,i][var[,i]<(p[,i][[2]])) and it returns num [1:49] -1.92 -1.69 -2.20 -1.65 -2.13 ... It is the number when i=1, I guess it does not loop. In fact, the number should be different when loop between i. jim holtman wrote: > > What does > > gpdlow(var[,i][var[,i]<(p[,i][[2]]

Re: [R] Loop and function

2007-07-05 Thread livia
Thanks. Yes, gpdlow is indeed return a vector longer than one. The length of the vector is different for i in 1:12, each equals to length(var[,i][var[,i]<(p[,i][[2]]). jim holtman wrote: > > What does > > gpdlow(var[,i][var[,i]<(p[,i][[2]]) > > return? Is it a vector; if so, how long? Yo

Re: [R] Loop and function

2007-07-05 Thread jim holtman
What does gpdlow(var[,i][var[,i]<(p[,i][[2]]) return? Is it a vector; if so, how long? Your declaration of > returnlow<- matrix(,12) > > str(returnlow) logi [1:12, 1] NA NA NA NA NA NA ... > is a matrix of 12 rows and one column. You may be getting the error message is gpdlow is returning a

Re: [R] Loop and function

2007-07-05 Thread livia
Thanks a lot. I have corrected this. But it still does not work. Any thought? Stephen Tucker wrote: > > You do not have matching parentheses in this line >returnlow <- gpdlow(var[,i][var[,i]<(p[,i][[2]]) > most likely there is a syntax error that halts the execution of the > assignment state

Re: [R] Loop and function

2007-07-05 Thread Stephen Tucker
You do not have matching parentheses in this line returnlow <- gpdlow(var[,i][var[,i]<(p[,i][[2]]) most likely there is a syntax error that halts the execution of the assignment statement? --- livia <[EMAIL PROTECTED]> wrote: > > Hi All, I am trying to make a loop for a function and I am us

Re: [R] Loop and function

2007-07-05 Thread jim holtman
Exactly how are you accessing it and what warnings are you getting. Your loop is just returning a single value; the last time i=12. If you want a vector of values back, the you have to do: returnlow <- numeric(12) for (i in 1:12){ gpdlow <- function(u){ p[,i]$beta -u*p[,i][[2]] }

[R] Loop and function

2007-07-05 Thread livia
Hi All, I am trying to make a loop for a function and I am using the following codes. "p" and "var" are some matrix obtained before. I would like to apply the function "gpdlow" for i in 1:12 and get the "returnlow" for i in 1:12. But when I ask for "returnlow" there are warnings and it turns out