Friday, 15 June 2012

Problems with defining the stucture of a list in R -



Problems with defining the stucture of a list in R -

i have function create list of different statistics computed follows:

riskstats = list(stdev,sharpe,downdev,sortino,maxdd,calmar,currdd) > riskstats [[1]] index stddev 3.2506 [[2]] index annualized sharpe ratio (rf=0%) -1.2434 [[3]] index downside deviation (mar = 0%) 3.194 [[4]] index sortino ratio (mar = 0%) -1.2655 [[5]] index maxdd -8.9467 [[6]] index calmar ratio -0.44846 [[7]] index current dd -8.543

i want set construction list (7 rows , 1 column) , can write

dim(riskstats) <- c(7,1)

why in results results [list,1] instead of right statistic computed?

> riskstats index annual volatility 3.2506 sharpe ratio -1.2434 downside deviation 3.194 sortino ratio -1.2655 maximum drawdown list,1 calmar ratio -0.44846 current drawdown list,1

using data

dput(riskstats) riskstats <- list(structure(list(index = 3.2506), .names = "index", row.names = "stddev", class = "data.frame"), structure(list(index = -1.2434), .names = "index", row.names = "annualized_sharpe_ratio_rf", class = "data.frame"), structure(list(index = 3.194), .names = "index", row.names = "downside_deviation_mar_0", class = "data.frame"), structure(list(index = -8.9467), .names = "index", row.names = "maxdd", class = "data.frame"), structure(list(index = -0.44846), .names = "index", row.names = "calmar_ratio", class = "data.frame"), structure(list(index = -8.543), .names = "index", row.names = "current_dd", class = "data.frame"))

you can accomplish goal several ways, here of them:

# alternative 1 (suggested @roman luštrik) do.call(rbind, riskstats) # think best 1 # alternative 2 reduce(rbind, riskstats) # alternative 3 t(data.frame(lapply(riskstats, t))) # it's not good, works.

whatever alternative chose end next result:

index stddev 3.25060 annualized_sharpe_ratio_rf -1.24340 downside_deviation_mar_0 3.19400 maxdd -8.94670 calmar_ratio -0.44846 current_dd -8.54300

r list

No comments:

Post a Comment