I am a beginner to use R to call C++ code for a fast computation. My toy.csv file has 3 rows and 2 columns with the same elements as in matrix(1:6, nrow=2, ncol=2) created by R. I want to create a toy.cpp file that reads data from toy.csv and assign it to x1 which is the same matrix as defined by matrix(1:6, nrow=2, ncol=2) in R, then perform the following calculation (I use R syntax):
x2=c(1,2)
y=c(0,0) #initial
for(i in 1:nrow(x1) {y[i]= sum(x[i, ] * x2)}
y
Could someone tell me how do I write the toy.cpp code to get result y? Thanks.