乘以R的百分比增加

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

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

我增加了200%+ 并且百分比也下降

评论
punde
punde

简单的情况:

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

If you don't want for some reason calculate the percentage, define a value without the %-sign

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

If you just have values with % you could transform them into numerical values

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

The regular expression uses removes all spaces and a following %. Hope this solves your issue.

点赞
评论