乘以 R 的百分比增加

Multiply by a percentage increase in R

如何将数字乘以 R 的百分比增加。例如

43424 增加 120% 将是 43424 * 2 + 43424 * 0.2

我增加了 200% + 百分比也有所下降

简单案例:

increase    <- 1.20
start_value <- 43424
inc_value   <- start_value * (1 + increase)

如果您出于某种原因不想计算百分比,请定义一个没有 %-符号的值

percentage  <- 120
increase    <- percentage/100
start_value <- 43424
inc_value   <- start_value * (1 + increase)

如果您只有 % 的值,您可以将它们转换为数值

percentage  <- c("120 %", "-200%")
increase    <- as.numeric(gsub("[[:space:]]*%", "", percentage))/100
start_value <- 43424
inc_value   <- start_value * (1 + increase)

正则表达式使用删除所有空格和后面的 %。希望这能解决您的问题。