<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>

CC BY-SA 4.0
2021-10-22T19:46:46.660Z
Please [format your code](https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks) so that it can be understood.
acvill
CC BY-SA 4.0
2021-10-23T14:40:50.770Z
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.
Community
CC BY-SA 4.0
2021-10-25T15:57:35.390Z
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.
Maximilian Press
<r>
Error in "apply(grps, 1, function(x) any(is.na(x))) : dim(X) must have a positive length" at running dht2 function in R
# 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

