如何在 R 中缩放中心为 100 的数据集?

How to scale a dataset with a center of 100 in R?

假设我有一组如下所示的值:

df$values <- c(1, 10, 5, 3, 8)

我想缩放此数据,使结果索引中的中值 5 为 100。由于 10 是 5 的两倍,因此其索引值为 200,依此类推

我如何在 R 中实现这一点?我知道 scale 函数,但我很难将它以 100 为中心。我是不是想错了?

你可以写一个函数-

scale_to <- function(x, val) x * val/median(x)

x <- c(1, 10, 5, 3, 8)
scale_to(x, 100)
#[1]  20 200 100  60 160

scale_to(x, 200)
#[1]  40 400 200 120 320