Body: <p>I am running the script from de Distance examples (<a href="http://examples.distancesampling.org/Distance-cues/cuecounts-distill.html" rel="nofollow noreferrer">http://examples.distancesampling.org/Distance-cues/cuecounts-distill.html</a>) to estimate density using function dht2 of Distance library but I have an error.</p>
  <p>The script is:</p>
  <pre><code>library (Distance)
  data(wren_cuecount)
  conversion.factor &lt;- convert_units(&quot;meter&quot;, NULL, &quot;hectare&quot;)
  wren_cuecount$Effort &lt;- wren_cuecount$Search.time
  wrensong.hr &lt;- ds(wren_cuecount, transect=&quot;point&quot;, key=&quot;hr&quot;, adjustment=NULL, 
                    truncation=100)
  cuerate &lt;- unique(wren_cuecount[ , c(&quot;Cue.rate&quot;,&quot;Cue.rate.SE&quot;)])
  names(cuerate) &lt;- c(&quot;rate&quot;, &quot;SE&quot;)
  (mult &lt;- list(creation=cuerate))
  wren.estimate &lt;- dht2(wrensong.hr, flatfile=wren_cuecount, strat_formula=~1,
                        multipliers=mult, convert_units=conversion.factor)
  print(wren.estimate, report=&quot;density&quot;)&quot;&quot;
  </code></pre>
  <p>When I run the dht2 function I get:</p>
  <blockquote>
  <p>Error in apply(grps, 1, function(x) any(is.na(x))) :    dim(X) must
  have a positive length</p>
  </blockquote>
  <p>How can I solve this?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-22T19:46:46.660Z
Comments.Text: Please [format your code](https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks) so that it can be understood.
Comments.UserDisplayName: acvill
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-23T14:40:50.770Z
Comments.Text: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Comments.UserDisplayName: Community
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-25T15:57:35.390Z
Comments.Text: I would suggest inspecting some of the intermediate objects such as `wrengsong.hr`, `wren_cuecount`, `mult`, etc. to ensure that they match the expected inputs of those functions.
Comments.UserDisplayName: Maximilian Press
Tags: <r>
Title: Error in "apply(grps, 1, function(x) any(is.na(x))) : dim(X) must have a positive length" at running dht2 function in R
ThreadText: # Error in "apply(grps, 1, function(x) any(is.na(x))) : dim(X) must have a positive length" at running dht2 function in R
  
  (Asked by: username_0 on 2021-10-22)
  
  I am running the script from de Distance examples (<http://examples.distancesampling.org/Distance-cues/cuecounts-distill.html>) to estimate density using function dht2 of Distance library but I have an error.
  
  The script is:
  
  ```
  library (Distance)
  data(wren_cuecount)
  conversion.factor <- convert_units("meter", NULL, "hectare")
  wren_cuecount$Effort <- wren_cuecount$Search.time
  wrensong.hr <- ds(wren_cuecount, transect="point", key="hr", adjustment=NULL, 
                    truncation=100)
  cuerate <- unique(wren_cuecount[ , c("Cue.rate","Cue.rate.SE")])
  names(cuerate) <- c("rate", "SE")
  (mult <- list(creation=cuerate))
  wren.estimate <- dht2(wrensong.hr, flatfile=wren_cuecount, strat_formula=~1,
                        multipliers=mult, convert_units=conversion.factor)
  print(wren.estimate, report="density")""
  
  ```
  
  When I run the dht2 function I get:
  
  > Error in apply(grps, 1, function(x) any(is.na(x))) : dim(X) must
  > have a positive length
  
  How can I solve this?
  
  **Tags:** r
  
  > **Comments:**
  > **username_1**: Please [format your code](https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks) so that it can be understood.  
  > **username_2**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  
  > **username_3**: I would suggest inspecting some of the intermediate objects such as `wrengsong.hr`, `wren_cuecount`, `mult`, etc. to ensure that they match the expected inputs of those functions.  
  
  ---
  
  ## 0 answers
  
  