This question might have been repeated. But even after going through the previous links, I am not able to solve this.
I am trying to use the formatDistData() function from the unmarked package, however, when running the code
yDat <- formatDistData(Detects1, distCol="distance", transectNameCol="transect", dist.breaks=db)
I get an error saying "The distances must be numeric"
. I have already ran the as.numeric() function but the code displays the same error.
Here is how my data looks. I have transect in one column and distance in the other. On the right you can see that distance is a num value and transect is chr. If someone is able to tell me what I need to do in order for it to work that would be great
transect,distance
NT1,14
NT1,14
NT1,20
NT1,20
NT1,10
NT1,15
> dput(Detects1)`
structure(list(transect = c("NT1", "NT1", "NT1", "NT1", "NT1",
"NT1", "NT1", "NT1", "NT1", "NT1", "NT2", "NT2", "NT2", "NT2",
"NT2", "NT2", "NT2", "NT2", "NT2", "NT2", "NT2", "NT2", "NT3",
"NT3", "NT3", "NT3", "NT3", "NT3", "NT3", "NT3", "NT3", "NT3",
"NT3", "NT3", "NT3", "NT3", "NT3", "NT3", "NT4", "NT3", "NT4",
"NT4", "NT4", "NT5", "NT5", "NT5", "NT5", "NT5", "SCC1", "SCC1",
"SCC1", "SCC1", "SCC1", "SCC1", "SCC1", "SCC1", "SCC3", "SCC3",
"SCC4", "SCC4", "SCC4", "SCC4", "SCC4", "SCC5", "SCC5", "SCC5",
"SCC5", "SCC5", "SCC5", "SCC5", "Urban1", "Urban1", "Urban1",
"Urban2", "Urban2", "Urban2", "Urban2", "Urban2", "Urban2", "Urban2",
"Urban4", "Urban4"), distance = c(14, 14, 20, 20, 10, 15, 5,
10, 15, 6, 10, 5, 5, 40, 7, 7, 5, 5, 12, 12, 2, 2, 5, 16, 6,
13, 3, 7, 5, 2, 0, 16, 10, 20, 20, 15, 10, 11, 17, 17, 12, 5,
3, 5, 8, 21, 12, 12, 15, 15, 7, 12, 3, 5, 6, 3, 2, 7, 8, 21,
5, 5, 11, 4, 12, 2, 1, 2, 5, 14, 10, 8, 3, 3, 11, 4, 9, 3, 7,
5, 2, 7)), .Names = c("transect", "distance"), row.names = c(NA,
-82L), spec = structure(list(cols = structure(list(transect =
structure(list(), class = c("collector_character",
"collector")), distance = structure(list(), class = c("collector_number",
"collector"))), .Names = c("transect", "distance")), default =
structure(list(), class = c("collector_guess",
"collector"))), .Names = c("cols", "default"), class = "col_spec"), class =
c("tbl_df", "tbl", "data.frame"))
The
dput
output shows me that you are providing atbl_df
(atidyverse
tibble) rather than a standarddata.frame
. It seems thatformatDistData
chokes on tibbles. If you do:It will work.
Note that you did not provide
db
, so I usedquantile
to define arbitrary breaks for the example to work.