Note that there are some explanatory texts on larger screens.

plurals
  1. POR zero or one based?
    text
    copied!<p>We have the following code in R (already stripped to the bone for debugging)</p> <pre><code>tgtStart = 29593 for (i in tgtStart:tgtStart) { PricerData[i, 1] = 111 } print(PricerData[29592,1]) </code></pre> <p>PricerData being a matrix constructed well beyond 29593 and pre filled with NAs.</p> <p>The thing I do not understand is that PricerData[29592, 1] will be changed to 111, this code prints 111, not the NA we expected.</p> <p>Just to make it a bit more elaborate, the code I ended with today was:</p> <pre><code>tgtStart = 29593 for (i in tgtStart:tgtStart) { print(PricerData[i,1]) print(PricerData[i-1,1]) PricerData[i, 1] = 111 print(PricerData[i,1]) print(PricerData[i-1,1]) } print(PricerData[29592,1]) </code></pre> <p>It will print:</p> <pre><code>[1] NA [1] NA [1] 111 [1] NA [1] 111 </code></pre> <p>All as expected till the end, why oh why is the element before our start changed? And why not in the loop, only after the closing of the for-loop (Oh and if we change the 29593 to 29596, all works as expected, me not comprehend.).</p> <p>Also, I don't code R, normally I'm doing C++, I'm to understand that R is one-based on it's vectors, but please do not mind to cover the real basics. We use R version 2.4.1.5, x64</p> <p>EDIT: Okay, it's clear that I cut too much from our code, so for you the problem went away, here is the full function, for reference, I do not understand the output it gives above</p> <pre><code>LoadPricer &lt;- function(instrument, colo, simDate, sliceSize, startTime, endTime, pricerName, pricerSettings, returnEmptyMatrixIfFileNotFound = FALSE) { fileName &lt;- paste ( simulatorOutputBasePath, instrument, '\\', colo, '\\', format(simDate, '%Y%m%d'), '\\', sliceSize, '\\P#', pricerName, '#', pricerSettings, '.csv', sep='') firstSliceRequest = GetSlicesSinceMidnight(startTime, sliceSize) lastSliceRequest = GetSlicesSinceMidnight(endTime, sliceSize) PricerData = as.matrix(matrix(NA, nrow=(lastSliceRequest - firstSliceRequest + 1), ncol = 1)) if (file.exists(fileName)) { # Load entire file AllData = as.data.frame(read.csv(fileName, header = TRUE, colClasses=c("customTimeFormat","numeric"))) if (dim(AllData)[1] &gt; 0) { firstSliceData = GetSlicesSinceMidnight(as.POSIXlt(AllData[1,1]), sliceSize) lastSliceData = GetSlicesSinceMidnight(as.POSIXlt(AllData[nrow(AllData),1]), sliceSize) if ( firstSliceData &lt;= lastSliceRequest &amp; lastSliceData &gt;= firstSliceRequest ) { tgtStart = max(1, firstSliceData - firstSliceRequest + 1) tgtEnd = min(lastSliceRequest - firstSliceRequest + 1, lastSliceData - firstSliceRequest + 1) srcStart = max(1, firstSliceRequest - firstSliceData + 1) srcEnd = min(lastSliceData - firstSliceData + 1, srcStart + tgtEnd - tgtStart) #PricerData[as.integer(tgtStart):as.integer(tgtEnd),1] = AllData[as.integer(srcStart):as.integer(srcEnd),2] for (i in tgtStart:tgtStart) { PricerData[i, 1] = 111# as.matrix(AllData[srcStart+i-tgtStart , 2]) } } } } else { if (returnEmptyMatrixIfFileNotFound) PricerData = matrix(NA, nrow=0, ncol=2) print(paste('WARNING: Unable to load Pricer! File:', fileName)) } return (PricerData) } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload