"if weight element is negative set it to zero, else recalculate the weights 
again"... this seems like the only way out of this loop is to calculate 
negative weights... and since you set them to zero at that point they will all 
be zero when you are done. Somehow I doubt that is what you intended to say.

On the other hand, if you had provided us with example input data and result 
data then we would not have to guess what you want.

I suspect that loops are not really what you want at all... but I could be 
wrong.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnew...@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On December 19, 2014 8:26:55 PM PST, Esra Ulasan <esra_ula...@icloud.com> wrote:
>Hello,
>
>I have tried the solve the non-negativity constraint "if else function"
>in R. But I have done something wrong because it still gives the same
>solution. I want that, if weight element is negative set it to zero,
>else recalculate the weights again. These are the codes:
>
> for(i in 1:M){ w[,i] = f+r[i]*g              #portfolio weights 
>    for(i in 1:M){
>      if (w <0){w=0}else{w=w}
>    }                     
>  } 
>If you help me I would be happy
>Thank you
>       [[alternative HTML version deleted]]
>
>______________________________________________
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to