这个问题可能已经重复了。但即使经过前面的链接,我也无法解决这个问题。
我正在尝试使用未标记包中的 formatDistData() 函数,但是,在运行代码时
yDat <- formatDistData(Detects1, distCol="distance", transectNameCol="transect", dist.breaks=db)
我收到一条错误消息"The distances must be numeric"
。我已经运行了 as.numeric() 函数,但代码显示相同的错误。
这是我的数据的外观。我在一列中有横切,另一列有距离。在右侧,您可以看到距离是 num 值,横断面是 chr。如果有人能够告诉我我需要做什么才能让它工作,那就太好了
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"))