gpt4 book ai didi

r - 如何按 AWS 调用的字节顺序对列表进行排序

转载 作者:行者123 更新时间:2023-12-02 09:31:20 25 4
gpt4 key购买 nike

看看http://associates-amazon.s3.amazonaws.com/signed-requests/helper/index.html

以下名称-值对:

Service=AWSECommerceService
Version=2011-08-01
AssociateTag=PutYourAssociateTagHere
Operation=ItemSearch
SearchIndex=Books
Keywords=harry+potter
Timestamp=2015-09-26T14:10:56.000Z
AWSAccessKeyId=123

The name-value pairs have been sorted according to byte-order

应该导致

AWSAccessKeyId=123
AssociateTag=PutYourAssociateTagHere
Keywords=harry%20potter
Operation=ItemSearch
SearchIndex=Books
Service=AWSECommerceService
Timestamp=2015-09-26T14%3A10%3A56.000Z
Version=2011-08-01

如何在 R 中实现这一点?

据我所知,它们是按其排序的as.numeric(charToRaw(name)) 值。如果第一个值相等,则按第二个值排序,然后是第三个值,依此类推。

问题:如何在 R 中执行此操作?

最佳答案

# Name-Value-Pairs
nvp <- list(
"Service"="AWSECommerceService",
"Version"="2011-08-01",
"AssociateTag"="PutYourAssociateTagHere",
"Operation"="ItemSearch",
"SearchIndex"="Books",
"Keywords"="harry potter",
"Timestamp"="2015-09-26T14:10:56.000Z",
"AWSAccessKeyId"="123"
)

获取字节:

bytes <- function(chr){
as.data.frame(t(as.numeric(charToRaw(chr))))
}

计算字节,并绑定(bind)值

b <- lapply(names(nvp), bytes)
b <- data.table::rbindlist(b, fill=TRUE) # other than base::rbind, this fills by NA

按第一列对名称进行排序,然后按第二列、第三列……依此类推

names(nvp)[do.call(order, as.list(b))]

[1] "AWSAccessKeyId" "AssociateTag" "Keywords" "Operation" "SearchIndex"
[6] "Service" "Timestamp" "Version"

最后nvp[do.call(order, as.list(b))] 返回正确排序的列表

关于r - 如何按 AWS 调用的字节顺序对列表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32798526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com