<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style></head><body lang=EN-US><div class=WordSection1><p class=MsoNormal>Dear list</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I am trying to create a simple Rcpp function that creates a three-dimensional array based on the values of a four-dimensional array. The arrays are declared as NumericVectors with a dim attribute represent the number of levels of each dimension. Here is a sample of the code:</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'>NumericVector sumby4(NumericVector X) {<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'> Dimension dim = X.attr("dim");<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'> if(dim.size() != 4) return NULL;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'> <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'> NumericVector ret = NumericVector::create(dim[0],dim[1],dim[2]);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'> for(int i = 0; i < dim[0]; i++) {<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'> for(int j = 0; j < dim[1]; j++) {<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'> for(int k = 0; k < dim[2]; k++) {<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'> ret(i,j,k) = NA_REAL;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'>…<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>When I attempt to compile the package in which this function resides, I get the error message associated with the “ret(I,j,k) = NA_REAL” line:</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>No match for call to Rcpp::NumericVector Rcpp::Vector<14 Rcpp::PreserveStorage>})(int&, int&, int&)</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I take from this message that the NumericVector ret cannot be indexed by three values, even though it has been dimensioned as a 3D array. What am I doing wrong here?</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Barth</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>