<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">dear serguei,</p>
<p style="margin-top:0;margin-bottom:0">                          Thanks...</p>
<p style="margin-top:0;margin-bottom:0">Can I also write this:</p>
<p style="margin-top:0;margin-bottom:0">M[1:i, n:m] as we write in R?</p>
<p style="margin-top:0;margin-bottom:0">If not, are there any packages that do it for me?</p>
<p style="margin-top:0;margin-bottom:0">what about RcppEigen?</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Basically, I want to write the following R code:</p>
<p style="margin-top:0;margin-bottom:0">{    p <- 1;</p>
<p style="margin-top:0;margin-bottom:0">             for(i in 550:nrow(x)){</p>
<p style="margin-top:0;margin-bottom:0">       y[p]  <- f(x[1:i,])</p>
<p style="margin-top:0;margin-bottom:0">          p <- p+1;</p>
<p style="margin-top:0;margin-bottom:0">          return(y)</p>
<p style="margin-top:0;margin-bottom:0">}</p>
<p style="margin-top:0;margin-bottom:0">in C++ using Rcpp. what is the best way to do that?</p>
<p style="margin-top:0;margin-bottom:0">x is an xts object containing OHLC historical stock prices of the stock x and f acts on the daily increments of x.</p>
<p style="margin-top:0;margin-bottom:0">very many thanks for your time and effort....</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">yours sincerely,</p>
<p style="margin-top:0;margin-bottom:0">AKSHAY M KULKARNI</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Serguei Sokol <serguei.sokol@gmail.com><br>
<b>Sent:</b> Tuesday, March 20, 2018 7:26:51 PM<br>
<b>To:</b> akshay kulkarni; Rcpp R<br>
<b>Subject:</b> Re: [Rcpp-devel] how to reference a row of a matrix in C++ in Rcpp</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Le 20/03/2018 à 12:10, akshay kulkarni a écrit :<br>
> dear members,<br>
> <br>
>                               I came to know from stackoverflow that the following references a row in a matrix in C++:<br>
> <br>
> M[2] references 2nd row of the Matrix.<br>
SO is too big to check this assertion by ourself. Do you have a link?<br>
<br>
> <br>
> <br>
> I am using Rcpp to write C++ code in R.<br>
> <br>
> <br>
> However, I ended up with the following inconsistency:<br>
> <br>
>  > M<br>
>       x y z<br>
> [1,] 1 1 1<br>
> [2,] 2 2 2<br>
> [3,] 3 3 3<br>
> [4,] 4 4 4<br>
> [5,] 5 5 5<br>
> [6,] 6 6 6<br>
>  > cppFunction('IntegerVector tccp3(IntegerMatrix M) { IntegerVector x = M[2]; return x;}')<br>
Try<br>
<br>
cppFunction('IntegerVector tccp3(IntegerMatrix M) { IntegerVector x = M(2,_); return x;}')<br>
<br>
Best,<br>
Serguei.<br>
<br>
<br>
>  > tccp3(M)<br>
> [1] 0 0 0<br>
>  > cppFunction('IntegerVector tccp4(IntegerMatrix M) { IntegerVector x = M[1]; return x;}')<br>
>  > tccp4(M)<br>
> [1] 0 0<br>
> <br>
> tccp3 should return (3,3,3) and tccp4 should return  (2,2,2). Can you please shed light on what is going on?<br>
> <br>
> very many thanks for your time and effort....<br>
> <br>
> Yours sincerely,<br>
> AKSHAY M KULKARNI<br>
> <br>
> <br>
> <br>
> _______________________________________________<br>
> Rcpp-devel mailing list<br>
> Rcpp-devel@lists.r-forge.r-project.org<br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
> <br>
<br>
</div>
</span></font></div>
</body>
</html>