- 已编辑
大家好,以下是資料,可以看到時間欄位沒有名稱
Mkt_RF,SMB,HML,RF
192607,2.96,-2.3,-2.87,0.22
192608,2.64,-1.4,4.19,0.25
192609,0.36,-1.32,0.01,0.23
192610,-3.24,0.04,0.51,0.32
192611,2.53,-0.2,-0.35,0.31
192612,2.62,-0.04,-0.02,0.28
因為發現直接讀取會全部都變成文字,所以加上colClasses 指定讀取型態,但卻出現錯誤
data <-
read.csv(
"C:/Users/Yoga/Desktop/F-F_Research_Data_Factors.csv",
header = T,
colClasses = c("character", rep("numeric", 4))
)
summary(data)
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : scan() 需要 'a real',而不是 'Mkt-RF'
因為是缺少欄位名稱,所以也有試過給定欄位名稱,可是結果也一樣
data <-
read.csv(
"C:/Users/Yoga/Desktop/F-F_Research_Data_Factors.csv",
header = T,col.names=c("time", "Mkt.RF", "SMB","HML","RF"),
colClasses = c("character", rep("numeric", 4))
)
請問是否有人知道改怎麼做,感謝
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] zh_TW.UTF-8/zh_TW.UTF-8/zh_TW.UTF-8/C/zh_TW.UTF-8/zh_TW.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2