[程式] R的數字處理

看板Statistics作者 (統計的巴比倫塔)時間15年前 (2010/08/03 17:57), 編輯推噓3(301)
留言4則, 4人參與, 最新討論串1/1
------------------------------------------------------------------------ [軟體程式類別]: R [程式問題]: 資料處理 [軟體熟悉度]: 請把以下不需要的部份刪除 中(3個月到1年) [問題敘述]: 請問如何將 1.125600e+04 轉換成 11256.00 因為我發現 R的一些函式會將 1.125600e+04 誤認成字串 比方說 tapply() 我觀察的結果 若一個 column 內 , 最大值與最小值差 10000 倍以上的時候 (含小數點) 會自動表示成 e+04 請問要怎麼把那個 e+04 去掉? 誠心請教 -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.239.247 ※ 編輯: gsuper 來自: 140.113.239.247 (08/03 17:58) ※ 編輯: gsuper 來自: 140.113.239.247 (08/03 18:03)

08/03 18:26, , 1F
?format
08/03 18:26, 1F

08/03 19:57, , 2F
round?
08/03 19:57, 2F
round() 不行 format() 我試了一下也沒找到要怎麼搞 我是拿以下這一串去測試 c(0.01,0.1,1,10,100) ※ 編輯: gsuper 來自: 140.113.239.247 (08/03 20:07)

08/03 20:47, , 3F
照你的例子,format(#your no.#, science=F, nsmall=2)
08/03 20:47, 3F
> format(c(0.01,0.1,1,10,100), scientific=F, nsmall=2) [1] " 0.01" " 0.10" " 1.00" " 10.00" "100.00" > as.numeric(format(c(0.01,0.1,1,10,100), scientific=F, nsmall=2)) [1] 1e-02 1e-01 1e+00 1e+01 1e+02 > as.factor(format(c(0.01,0.1,1,10,100), scientific=F, nsmall=2)) [1] 0.01 0.10 1.00 10.00 100.00 Levels: 0.01 0.10 1.00 10.00 100.00 ※ 編輯: gsuper 來自: 140.113.239.247 (08/03 21:11)

08/04 10:34, , 4F
formatC(1.125600e+04, format="d")
08/04 10:34, 4F
> formatC(c(0.01,0.1,1,10,100),format="d",digits=2) [1] "0" "0" "1" "10" "100" > formatC(c(0.01,0.1,1,10,100),format="fg",digits=2) [1] "0.01" "0.1" " 1" " 10" "100" 轉完以後都是字串 看起來還是只能用 as.factor 來轉 ※ 編輯: gsuper 來自: 140.113.239.247 (08/04 14:47) ※ 編輯: gsuper 來自: 140.113.239.247 (08/04 14:49)
文章代碼(AID): #1CL-V_HX (Statistics)