R 如何确保数字是.txt中的数字?

R 如何确保数字是.txt中的数字?,r,categorical-data,weibull,numerics,R,Categorical Data,Weibull,Numerics,我正在设置一个脚本,从单列文本文件中提取厚度和电压,并对其执行威布尔分布。当我尝试使用FitDisr时,我得到一个错误,指出“x”必须是非空的数值向量。R应该将文本文件中的数字解释为数字,但这似乎没有发生。有什么想法吗 filename <- "SampleBreakdownSet.txt" d <- read.table(filename, header = FALSE, sep = "") #Extract thickness from the dataset; set to

我正在设置一个脚本,从单列文本文件中提取厚度和电压,并对其执行威布尔分布。当我尝试使用FitDisr时,我得到一个错误,指出“x”必须是非空的数值向量。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)
您正在向FitDisr传递data.frame,但应该传递向量本身

试试这个:

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)

我建议检查strd和summary的结果。我尝试了第二种方法,将列设置为FitDisr,效果很好。我仍然习惯于事物的数据类型。再次感谢。
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(BDF$V1, densfun ="weibull", lower = 0)

#       shape          scale    
#   2.745485e+00   1.997509e+04 
#  (3.716797e-01) (1.283667e+03)