<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">                         I have another question:</p>
<p style="margin-top:0;margin-bottom:0">If M is a matrix, M.nrow() should return the number of rows...but I encountered the following inconsistency:</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"></p>
<div>> M</div>
<div>     x  y  z</div>
<div>[1,] 1  0  0</div>
<div>[2,] 4  3  0</div>
<div>[3,] 3  1  1</div>
<div>[4,] 2 90 87</div>
<div>[5,] 9 76 23</div>
<div>[6,] 5 23 13</div>
<div>> cppFunction('IntegerVector tccp5(IntegerMatrix M) { int x = M.nrow(); return x;}')</div>
<div>> tccp5(M)</div>
<div>[1] 0 0 0 0 0 0</div>
<div><br>
</div>
<div>can you please explain what is happening( I am very new to Rcpp and C++)?</div>
<div><br>
</div>
<div>very many thanks for your time and effort...</div>
<div>yours sincerely,</div>
<div>AKSHAY M KULKARNI</div>
<br>
<p></p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<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 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" id="LPlnk49532" previewremoved="true">
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a>
<div id="LPBorder_GT_15216214498320.608126722615115" style="margin-bottom: 20px; overflow: auto; width: 100%; text-indent: 0px;">
<table id="LPContainer_15216214498220.5107747557176499" role="presentation" cellspacing="0" style="width: 90%; background-color: rgb(255, 255, 255); position: relative; overflow: auto; padding-top: 20px; padding-bottom: 20px; margin-top: 20px; border-top: 1px dotted rgb(200, 200, 200); border-bottom: 1px dotted rgb(200, 200, 200);">
<tbody>
<tr valign="top" style="border-spacing: 0px;">
<td id="TextCell_15216214498260.7928294121648589" colspan="2" style="vertical-align: top; position: relative; padding: 0px; display: table-cell;">
<div id="LPRemovePreviewContainer_15216214498260.1714432957520733"></div>
<div id="LPTitle_15216214498260.37040246346645267" style="top: 0px; color: rgb(0, 120, 215); font-weight: 400; font-size: 21px; font-family: wf_segoe-ui_light, "Segoe UI Light", "Segoe WP Light", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; line-height: 21px;">
<a id="LPUrlAnchor_15216214498290.2545223287950973" href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank" style="text-decoration: none;">Rcpp-devel Info Page</a></div>
<div id="LPMetadata_15216214498290.566507500315679" style="margin: 10px 0px 16px; color: rgb(102, 102, 102); font-weight: 400; font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; line-height: 14px;">
lists.r-forge.r-project.org</div>
<div id="LPDescription_15216214498300.4805153422582842" style="display: block; color: rgb(102, 102, 102); font-weight: 400; font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; line-height: 20px; max-height: 100px; overflow: hidden;">
Discussion list for Rcpp, RInside and various packages using Rcpp or RInside. This list is subscriber-only, in other words in order to post to the list you must be ...</div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
> <br>
<br>
</div>
</span></font></div>
</div>
</div>
</body>
</html>