[R] Loop and function

livia yn19832 at msn.com
Thu Jul 5 15:49:06 CEST 2007


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]])
> 
> 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 vector longer than one.  Do
> 
> str(gpdlow(var[,i][var[,i]<(p[,i][[2]]))
> 
> so that we can see what the data looks like.  You still haven't provided a
> self-contained example, so we can only guess at what is happening.
> 
> 
> 
> On 7/5/07, livia <yn19832 at msn.com> wrote:
>>
>>
>> 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 statement?
>> >
>> >
>> >
>> > --- livia <yn19832 at msn.com> wrote:
>> >
>> >>
>> >> 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
>> >> some strange result.
>> >>
>> >> for (i in 1:12){
>> >> gpdlow <- function(u){
>> >> p[,i]$beta -u*p[,i][[2]]
>> >> }
>> >> returnlow <- gpdlow(var[,i][var[,i]<(p[,i][[2]])
>> >> }
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/Loop-and-function-tf4028854.html#a11443955
>> >> Sent from the R help mailing list archive at Nabble.com.
>> >>
>> >> ______________________________________________
>> >> R-help at stat.math.ethz.ch mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>> >> PLEASE do read the posting guide
>> >> http://www.R-project.org/posting-guide.html
>> >> and provide commented, minimal, self-contained, reproducible code.
>> >>
>> >
>> > ______________________________________________
>> > R-help at stat.math.ethz.ch mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Return-valus-for-different-numbr-of-rows-tf4028854.html#a11445807
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> 
> 
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
> 
> What is the problem you are trying to solve?
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/Return-valus-for-different-numbr-of-rows-tf4028854.html#a11446873
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list