r - PerformanceAnalytics Numbers to Percent % -
i want know if possible make table output in r package % instead of numeric.
table.annualizedreturns(indover, rf=0) sp500 annualized return 0.0732 annualized std dev 0.1951 annualized sharpe (rf=0%) 0.3752
so 1st 1 0.0732 see 0.07%
the return value function data frame, question how make column of data frame print percentage sign.
reproducible example follows.
> require(performanceanalytics) > data(managers) > tb = table.annualizedreturns(managers[,1],rf=0) > tb ham1 annualized return 0.1375 annualized std dev 0.0888 annualized sharpe (rf=0%) 1.5491
now define new class , format function displays percent sign:
> format.pc = function(x,...){sprintf('%0.2f%%',x)} > class(tb[,1])="pc"
and now, if magic:
> tb ham1 annualized return 0.14% annualized std dev 0.09% annualized sharpe (rf=0%) 1.55%
the underlying values have not been changed:
> tb[,1] [1] 0.1375 0.0888 1.5491 attr(,"class") [1] "pc"
they in vector of new class.
Comments
Post a Comment