Home > Mobile >  return an output with % format in R
return an output with % format in R

Time:12-22

library(scales)
traded_price<-10
market_price<-9
breakeven<-function(traded_price, market_price){
  percent<-label_percent(1-(traded_price/market_price))
  percent
}

output should then be 1-(10/9), which is a 10% percent to be breakeven, however, the return is as below:

> breakeven(10,9)
function (x) 
number(x, accuracy = accuracy, scale = scale, prefix = prefix, 
    suffix = suffix, big.mark = big.mark, decimal.mark = decimal.mark, 
    trim = trim, ...)

May I know what have I do wrong in writing this function? Thanks a lot.

CodePudding user response:

breakeven <- function(traded_price, market_price){
  prcnt <- (1 - (traded_price / market_price))
  scales::percent(prcnt)
}

breakeven(10, 9)
#> [1] "-11%"

Created on 2022-12-21 with reprex v2.0.2

  • Related