# 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"
)
Get Bytes:
bytes <- function(chr){
as.data.frame(t(as.numeric(charToRaw(chr))))
}
Calculate Bytes, and rbind the values
b <- lapply(names(nvp), bytes)
b <- data.table::rbindlist(b, fill=TRUE) # other than base::rbind, this fills by NA
Order the names by first column, then by second, by third, ... and so on
names(nvp)[do.call(order, as.list(b))]
[1] "AWSAccessKeyId" "AssociateTag" "Keywords" "Operation" "SearchIndex"
[6] "Service" "Timestamp" "Version"
So finally nvp[do.call(order, as.list(b))]
returns in the properly sorted list
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…