Note that there are some explanatory texts on larger screens.

plurals
  1. POMatrix algebra on a rolling subset of data in R
    primarykey
    data
    text
    <p>I am a novice to R and have the following problem:</p> <p><strong>Data Input</strong>:</p> <p>I have a CSV with two columns like this:</p> <pre><code>1,10 2,20 3,30 4,40 5,50 ... N, M </code></pre> <p><strong>Problem:</strong></p> <pre><code>a) Read in the CSV b) Convert to a matrix c) Take 4 rows starting with the first row d) calculate the third column of elements as a simple square of the second column elements e) Calculate the sumproduct (value11*value12*value13 + value21*value22*value23 + value31*value32*value33 +value41*value42*value43) f) Do this until the end of the dataset </code></pre> <p>Outcome:</p> <p>The result for the first two matrices should be as follows:</p> <p><strong>First matrix:</strong></p> <p>Start with the first row, select four rows.</p> <p>Step 1</p> <pre><code>1,10 2,20 3,30 4,40 </code></pre> <p>Step 2 (add the 3rd column as a square of the second column value)</p> <pre><code>1,10,100 2,20,400 3,30,900 4,40,1600 </code></pre> <p>Step 3 (calculate the sumproduct) (1*10*100 + 2*20*400 +3*30*900 + 4*40*1600) == 354.000</p> <p><strong>Second matrix:</strong></p> <p>Proceed with the second row and take the next 4 rows</p> <p>Step 1</p> <pre><code>2,20 3,30 4,40 5,50 </code></pre> <p>Step 2 (add the 3rd column as a square of the second column value)</p> <pre><code>2,20,400 3,30,900 4,40,1600 5,50,2500 </code></pre> <p>Step 3 (calculate the sumproduct)</p> <pre><code>(2*20*400 +3*30*900 + 4*40*1600 + 5*50*2500) == 978.000 </code></pre> <p><strong>N matrix</strong> Do steps 1 to 3 until the end of the dataset</p> <p><strong>RESULT</strong> </p> <p>The result should be the list of sumproducts:</p> <pre><code>354.000, 978.000, ..., N </code></pre> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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