2017-09-14 14 views
0

この質問は繰り返されている可能性があります。しかし、以前のリンクを経ても、私はこれを解決することができません。formatDistData()、距離は数値である必要があります

コード

yDat <- formatDistData(Detects1, distCol="distance", transectNameCol="transect", dist.breaks=db) 

を実行しているとき、私は、しかし、マークされていないパッケージからformatDistData()関数を使用しようとしていますが、私は"The distances must be numeric"を言って、エラーを取得します。私はすでにas.numeric()関数を実行していますが、コードは同じエラーを表示します。

私のデータは次のようになります。私はある列にトランセクト、もう一方の列にトランセクトを持っています。右側では、距離がnum値でtransectがchrであることがわかります。誰かが私はそれを動作させるために何をする必要があるかを私に伝えることができる場合にはそれは素晴らしいことだ

Data

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")) 
+0

データの簡単な例を貼り付けやすい形式で入力してください。 –

+0

問題を再現できるようにすると役に立ちます:https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example –

+0

@RomanLuštrik大丈夫ですか? – Jamie

答えて

0

dput出力は、tbl_dftidyverse tibble)を提供していることを私に示して標準ではなくdata.frameです。はチブルのチョークのようです。あなたがする場合:

library(unmarked) 
yDat <- formatDistData(
    as.data.frame(Detects1), # coerce to standard data.frame 
    distCol="distance", 
    transectNameCol="transect", 
    dist.breaks = quantile(Detects1$distance, seq(0.1, 0.9, by = 0.1))) 

それは動作します。

dbを提供していないので、私はquantileを使用して、この例が機能するように任意の区切りを定義しました。

関連する問題