![](/img/trans.png)
[英]How do I make sure my textInput in Shiny only accepts numeric values?
[英]How do I make sure numbers are numeric from a .txt?
我正在設置一個腳本,以從單列文本文件中提取厚度和電壓,並對其執行Weibull分布。 當我嘗試使用fitdistr()
,出現錯誤,指出“ 'x' must be a non-empty numeric vector
”。 R應該將文本文件中的數字解釋為數字,但這似乎沒有發生。 有什么想法嗎?
filename <- "SampleBreakdownSet.txt"
d <- read.table(filename, header = FALSE, sep = "")
#Extract thickness from the dataset; set to variable t
t = d[1,1]
#Extract the breakdown voltages and toss into dataset, BDV
BDV = tail(d,(nrow(d)-1))
#Calculates the breakdown field from the thickness and BDV
BDF = (BDV*10000) / t
#Calculates the Weibull parameters from the input breakdown voltages.
fitdistr(BDF, densfun ="weibull", lower = 0)
fitdistr(BDF,densfun =“ weibull”,lower = 0)fitdistr(BDF,densfun =“ weibull”,lower = 0)錯誤:'x'必須是非空數值向量
我正在使用的樣本數據:2
200
250
450
320
100
400
200
403
502
203
420
120
342
304
253
423
534
534
243
253
423
123
433
534
234
633
432
342
543
532
123
453
231
532
342
213
243
您正在將data.frame
傳遞給fitdistr
,但是您應該傳遞矢量本身。
嘗試這個:
d <- read.table(text='200
250
450
320
100
400
200
403
502
203
420
120
342
304
253
423
534
534
243
253
423
123
433
534
234
633
432
342
543
532
123
453
231
532
342
213
243', header=FALSE)
t <- d[1,1]
#Extract the breakdown voltages and toss into dataset, BDV
BDV <- d[-1, 1]
BDF <- (BDV*10000) / t
library(MASS)
fitdistr(BDF, densfun ="weibull", lower = 0)
您還可以在調用fitdistr
時參考相關列,例如:
fitdistr(BDF$V1, densfun ="weibull", lower = 0)
# shape scale
# 2.745485e+00 1.997509e+04
# (3.716797e-01) (1.283667e+03)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.