如何在TCL中对嵌套词典进行排序

时间:2019-10-29 04:11:23

标签: tcl

我在TCL中有一个嵌套的字典,其中特定索引处的值未按子索引值进行排序,例如在此字典中,我想对55,21,36进行排序,并在排序时移动子项,我也想同时在其子键周围移动时对103,344,3进行排序

我很困惑如何去做这样的事情。我无法使用lsort -index -stride,因为我的子词典不是单个扁平化列表

require(dplyr)
require(plyer)
require(data.table)
require(jsonlite)
require(httr)
require(rvest)
require(XML)
require(plyr)


COLORDER = c("symbol", "code", "type", "expiry", "strike", "premium", "bid", "ask", "volume", "open.interest", "retrieved")


# AUSTRALIAN OPTIONS --------------------------------------------------------------------------------------------------

# ASX is the Australian Securities Exchange.

URLASX = 'http://www.asx.com.au/asx/markets/optionPrices.do?by=underlyingCode&underlyingCode=%s&expiryDate=&optionType=B'

getOptionChainAsx <- function(symbol) {
  url = sprintf(URLASX, symbol)

  html <- read_html(url)

  # Use the second element in the list (the first element gives data on the underlying stock)
  #
  options = (html %>% html_nodes("table.options") %>% html_table(header = TRUE))[[2]] %>%
    plyr::rename(c("Bid" = "bid", "Offer" = "ask", "Openinterest" = "open.interest", "Volume" = "volume", "Expirydate" = "expiry",
                   "P/C" = "type", "Margin Price" = "premium", "Exercise" = "strike", "Code" = "code")) %>%
    transform(
      symbol        = symbol,
      code          = code,
      retrieved     = Sys.time(),
      open.interest = suppressWarnings(as.integer(gsub(",", "", open.interest))),
      premium       = suppressWarnings(as.numeric(premium)),
      bid           = suppressWarnings(as.numeric(bid)),
      ask           = suppressWarnings(as.numeric(ask)),
      volume        = suppressWarnings(as.integer(gsub(",", "", volume))),
      expiry        = as.Date(expiry, format = "%d/%m/%Y")
    ) %>% dplyr::arrange(type, strike, expiry)
  options[, COLORDER]
}

getOptionChainAsx("BHP")

预期的输出1 [基于21、36、55 [最终子值]进行排序,其中55一直以其键结束直到最后]

a1,a2 {0,6 {103 55} 1,5 {344 21} 6,7 {3 36}}

预期的输出2 [基于344,3,103,344的排序及其键一直到最后]

a1,a2 {1,5 {344 21} 6,7 {3 36} 0,6 {103 55}}

0 个答案:

没有答案
相关问题