如何在 R 中求表示科学记数法中非常小的数字的平均值?
如果我们找到科学数字的平均值,则结果也将采用科学记数法。我们可以通过使用 options(scipen=999) 来摆脱这个问题,一旦我们在 R 控制台中使用此代码,所有采用科学记数法的输入都将转换为正常的数字形式,包括任何计算,并且如果我们想要返回到科学记数法,可以使用 options(scipen=0)。
示例
> x1<-c(4.225867e-23,3.463125e-24,2.480971e-35,1.660538e-26,1.074064e-37,6.829168e-29,4.305051e-21,2.702241e-27,1.692533e-29,1.058970e-29,6.622117e-34,4.139935e-36,2.587807e-37,1.617488e-38,1.010964e-39,6.318630e-21,3.949177e-22,2.468246e-23,1.542657e-24,9.641616e-26,6.026013e-27,3.766259e-28,2.353912e-29,1.471195e-30,9.194971e-32) > mean(x1)
输出
[1] 4.436267e-22
示例
> options(scipen=999) > mean(x1)
输出
[1] 0.0000000000000000000004436267
示例
> x2<-sample(c(4.225867e-23,3.463125e-24,2.480971e-35,1.660538e-26,1.074064e-37,6.829168e-29,4.305051e-21,2.702241e-27,1.692533e-29,1.058970e-29,6.622117e-34,4.139935e-36,2.587807e-37,1.617488e-38,1.010964e-39,6.318630e-21,3.949177e-22,2.468246e-23,1.542657e-24,9.641616e-26,6.026013e-27,3.766259e-28,2.353912e-29,1.471195e-30,9.194971e-32),50,replace=TRUE) > x2
输出
[1] 0.000000000000000000000000000000000000001010964 [2] 0.000000000000000000000000000068291679999999998 [3] 0.000000000000000000000000006026013000000000181 [4] 0.000000000000000000000000002702241000000000107 [5] 0.000000000000000000000042258669999999998179163 [6] 0.000000000000000000000000000000091949710000000 [7] 0.000000000000000000000000000000000000107406400 [8] 0.000000000000000000000000000000091949710000000 [9] 0.000000000000000000000003463124999999999951636 [10] 0.000000000000000000004305051000000000103323794 [11] 0.000000000000000000000001542657000000000059366 [12] 0.000000000000000000000000002702241000000000107 [13] 0.000000000000000000000000000001471195000000000 [14] 0.000000000000000000000000006026013000000000181 [15] 0.000000000000000000000000000000000000001010964 [16] 0.000000000000000000000000000000000000107406400 [17] 0.000000000000000000000001542657000000000059366 [18] 0.000000000000000000000000096416159999999999745 [19] 0.000000000000000000000000096416159999999999745 [20] 0.000000000000000000000000000000091949710000000 [21] 0.000000000000000000000000000001471195000000000 [22] 0.000000000000000000000000016605380000000000407 [23] 0.000000000000000000000000000023539120000000001 [24] 0.000000000000000000006318630000000000014343665 [25] 0.000000000000000000000000000000000000016174880 [26] 0.000000000000000000000003463124999999999951636 [27] 0.000000000000000000000000000000000000016174880 [28] 0.000000000000000000000000000068291679999999998 [29] 0.000000000000000000004305051000000000103323794 [30] 0.000000000000000000000042258669999999998179163 [31] 0.000000000000000000000000000000000662211700000 [32] 0.000000000000000000000024682460000000000627761 [33] 0.000000000000000000000024682460000000000627761 [34] 0.000000000000000000000000000068291679999999998 [35] 0.000000000000000000000394917700000000012347870 [36] 0.000000000000000000000000000000000024809710000 [37] 0.000000000000000000000000000068291679999999998 [38] 0.000000000000000000000000000000000000001010964 [39] 0.000000000000000000000042258669999999998179163 [40] 0.000000000000000000000000000023539120000000001 [41] 0.000000000000000000000024682460000000000627761 [42] 0.000000000000000000006318630000000000014343665 [43] 0.000000000000000000000000000000000000016174880 [44] 0.000000000000000000000000000010589700000000000 [45] 0.000000000000000000000000000000091949710000000 [46] 0.000000000000000000004305051000000000103323794 [47] 0.000000000000000000000000000000000024809710000 [48] 0.000000000000000000000000000010589700000000000 [49] 0.000000000000000000000001542657000000000059366 [50] 0.000000000000000000000000006026013000000000181
示例
> mean(x2)
输出
[1] 0.0000000000000000000005231988
示例
> x3<-sample(c(4.225867e-23,3.463125e-24,2.480971e-35,1.660538e-26,1.074064e-37,6.829168e-29,4.305051e-21),50,replace=TRUE) > x3
输出
[1] 0.0000000000000000000043050510000000001033238 [2] 0.0000000000000000000043050510000000001033238 [3] 0.0000000000000000000000034631249999999999516 [4] 0.0000000000000000000043050510000000001033238 [5] 0.0000000000000000000000000000682916800000000 [6] 0.0000000000000000000043050510000000001033238 [7] 0.0000000000000000000000034631249999999999516 [8] 0.0000000000000000000000034631249999999999516 [9] 0.0000000000000000000000034631249999999999516 [10] 0.0000000000000000000043050510000000001033238 [11] 0.0000000000000000000000422586699999999981792 [12] 0.0000000000000000000043050510000000001033238 [13] 0.0000000000000000000000422586699999999981792 [14] 0.0000000000000000000000000000000000001074064 [15] 0.0000000000000000000000000000000000001074064 [16] 0.0000000000000000000043050510000000001033238 [17] 0.0000000000000000000043050510000000001033238 [18] 0.0000000000000000000043050510000000001033238 [19] 0.0000000000000000000000000000000000248097100 [20] 0.0000000000000000000000000000682916800000000 [21] 0.0000000000000000000000000000682916800000000 [22] 0.0000000000000000000000000166053800000000004 [23] 0.0000000000000000000000034631249999999999516 [24] 0.0000000000000000000000000000000000001074064 [25] 0.0000000000000000000000000000682916800000000 [26] 0.0000000000000000000000000166053800000000004 [27] 0.0000000000000000000000000000000000001074064 [28] 0.0000000000000000000000000000000000001074064 [29] 0.0000000000000000000000000000000000248097100 [30] 0.0000000000000000000000000000000000248097100 [31] 0.0000000000000000000000000000000000001074064 [32] 0.0000000000000000000000000000682916800000000 [33] 0.0000000000000000000000034631249999999999516 [34] 0.0000000000000000000000000166053800000000004 [35] 0.0000000000000000000043050510000000001033238 [36] 0.0000000000000000000000000000000000001074064 [37] 0.0000000000000000000000000000000000001074064 [38] 0.0000000000000000000000000166053800000000004 [39] 0.0000000000000000000000034631249999999999516 [40] 0.0000000000000000000000000000682916800000000 [41] 0.0000000000000000000000000000000000248097100 [42] 0.0000000000000000000000000000000000248097100 [43] 0.0000000000000000000000034631249999999999516 [44] 0.0000000000000000000000000000000000001074064 [45] 0.0000000000000000000000000000682916800000000 [46] 0.0000000000000000000000000000000000001074064 [47] 0.0000000000000000000000000000000000001074064 [48] 0.0000000000000000000000000000000000001074064 [49] 0.0000000000000000000000000166053800000000004 [50] 0.0000000000000000000000000166053800000000004
示例
> mean(x3)
输出
[1] 0.0000000000000000000008632566
广告