[R] Bug in my code (finding nonzero min)
gunter.berton at gene.com
Mon Jul 23 07:03:58 CEST 2012
!!! Well, that strikes me as a fair bit of chutzpah. Some generous
soul may well respond, but why not do your own debugging using R's
debugging tools.It will serve you well in the long run to put in the
effort now to learn them. Debugging is a major part of any
... and the "error" settingt of options()
are a place to start.
If you check this list's archives you'll find other similar queries
and helpful debugging tips.
On Sun, Jul 22, 2012 at 9:34 PM, wwreith <reith_william at bah.com> wrote:
> Can someone verify for me if the for loop below is really calculating the
> nonzero min for each row of a matrix? I have a bug somewhere in the is
> section of code. My first guess is how I am find the the nonzero min of each
> row of my matrix. The overall idea is to make sure I am investing all of my
> money, i.e. new.set is a set of indicator variables for each stock for a
> particular portfolio, i.e. 0=did not buy, 1=bought. y are the stocks I could
> still buy, assuming I have the money, data3[,5] are their cost, so for each
> portfolio, i.e. the rows of new.set I have the option to purchase another
> stock at a cost listed in the rows of variable remain. Obvisouly the
> cheapest stock needs to have a cost>0 in order for me to be allowed to buy
> it. My code is intended to weed out portfolios where I could have bought
> another stock, by taking budget-portfolio cost - (cheapest available stock)
> and subsetting new.set when this is negative, i.e. buying the cheapest
> available stock puts me over budget. My problem is that my code is still
> allowing examples like the following budget of 10, portfolio cost 6,
> cheapest availabe stock 3 despite the diff variable being negative.
> Any ideas?
> for(q in 1:nrow(remain))
> View this message in context: http://r.789695.n4.nabble.com/Bug-in-my-code-finding-nonzero-min-tp4637399.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Genentech Nonclinical Biostatistics
Internal Contact Info:
More information about the R-help