将“(3e + 04,3.5e + 04)”类型转换为r中的数字

时间:2015-04-25 09:55:37

标签: r formatting

我有道路上车速的数据集,以及从测量起点开始的汽车距离。

我想检查一下每5公里的平均值和se是多少,所以我按“DistanceFromStart”对数据进行了排序,并使用我构建的函数创建了一个表:

speedByKM <- function(testFile){
     setDT(a1a2011)[, list(Speed=mean(Speed)), by=list(cut(DistanceFromStart,breaks= seq(0, max(DistanceFromStart)+5000, by = 5000),include.lowest=TRUE))]->res
    setDT(a1a2011)[, list(Speed=se(Speed)), by=list(cut(DistanceFromStart,breaks= seq(0, max(DistanceFromStart)+5000, by = 5000),include.lowest=TRUE))]->res1
    res$se = res1$Speed 
       return(res)
 }

我得到的表是:

            cut    Speed         se
1: (3e+04,3.5e+04] 88.16993 0.04784163

2:   (5e+03,1e+04] 94.33507 0.02121293

3: (2e+04,2.5e+04] 99.26032 0.03680951

4: (2.5e+04,3e+04] 90.31163 0.03991980

5:       [0,5e+03] 94.69139 0.01872111

6: (1e+04,1.5e+04] 94.70515 0.02661366

7: (1.5e+04,2e+04] 97.34650 0.02880336

如何将KM显示为数字? 例如,而不是'5e + 03'显示5000? 谢谢。

1 个答案:

答案 0 :(得分:2)

dig.lab参数从其默认值3增加:

x <- (1:5) * 1e3

cut(x, c(500, 2500, 5000))
#[1] (500,2.5e+03]   (500,2.5e+03]   (2.5e+03,5e+03] (2.5e+03,5e+03] (2.5e+03,5e+03]
#Levels: (500,2.5e+03] (2.5e+03,5e+03]
cut(x, c(500, 2500, 5000), dig.lab = 4L)
#[1] (500,2500]  (500,2500]  (2500,5000] (2500,5000] (2500,5000]
#Levels: (500,2500] (2500,5000]