压平或平滑一系列数字

时间:2018-04-18 20:23:20

标签: r flatten smoothing

我的问题是关于平滑或压扁一系列数字。我搜索了选项,但没有找到任何选项。在我的示例数据集中:

dat <- list(-21,-18,-16,-10,-8,-4,-3,-2,-1,-0.9,-0.7,-0.5,-0.3,-0.1,0,0.2,0.4,0.6,0.8,1,2,4,6,9,13,17,20,24)

我想以对数方式平坦或平滑数据,可能是这样的(数字四舍五入到小数点后一位):

smooth<-list(-4.6,-4.2,-4,-3.2,-2.8,-2,-1.7,-1.4,-1,-0.9,-0.8,-0.7,-0.5,-0.3,0,0.4,0.6,0.8,0.9,1,1.4,2,2.4,3,3.6,4.1,4.5,4.9)

以上是原件的平方根;但是,对于负数必须改变符号,在我的情况下,也不希望1和-1之间的数字的绝对值实际上增加而不是减少。我能够构建上述内容,但这并不容易或理想,我想知道是否有更简单和更好的程序。 谢谢。

1 个答案:

答案 0 :(得分:1)

这样的事情怎么样:

sign(dat)*log(abs(dat)+1)

plot(dat, col = "red")
points(smooth, col = "green")
points(sign(dat)*log(abs(dat)+1), col = "blue")
legend(x = 1, y = 23, legend = c("original", "smooth", "missuse"),
       fill = c("red", "green", "blue"))

enter image description here

使用log2:

enter image description here

数据:

dat <- c(-21,-18,-16,-10,-8,-4,-3,-2,-1,-0.9,-0.7,-0.5,-0.3,-0.1,0,0.2,
          0.4,0.6,0.8,1,2,4,6,9,13,17,20,24)

smooth <- c(4.6,-4.2,-4,-3.2,-2.8,-2,-1.7,-1.4,-1,-0.9,-0.8,-0.7,-0.5,-0.3,0,0.4,0.6,
            0.8,0.9,1,1.4,2,2.4,3,3.6,4.1,4.5,4.9)