I am a novice to R and have the following problem:
Data Input:
I have a CSV with two columns like this:
1,10
2,20
3,30
4,40
5,50
...
N, M
Problem:
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
Outcome:
The result for the first two matrices should be as follows:
First matrix:
Start with the first row, select four rows.
Step 1
1,10
2,20
3,30
4,40
Step 2 (add the 3rd column as a square of the second column value)
1,10,100
2,20,400
3,30,900
4,40,1600
Step 3 (calculate the sumproduct) (1*10*100 + 2*20*400 +3*30*900 + 4*40*1600) == 354.000
Second matrix:
Proceed with the second row and take the next 4 rows
Step 1
2,20
3,30
4,40
5,50
Step 2 (add the 3rd column as a square of the second column value)
2,20,400
3,30,900
4,40,1600
5,50,2500
Step 3 (calculate the sumproduct)
(2*20*400 +3*30*900 + 4*40*1600 + 5*50*2500) == 978.000
N matrix Do steps 1 to 3 until the end of the dataset
RESULT
The result should be the list of sumproducts:
354.000, 978.000, ..., N
Thank you!