展平或平滑一系列数字

Flatten or Smoothing a Series of Numbers

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

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 之间的数字的绝对值实际上增加而不是减少也是不可取的。我能够构建上面的内容,但这并不容易或不理想,我想知道是否有更简单更好的程序。 谢谢。

这样的事情怎么样:

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"))

log2:

数据:

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)