Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
英数字以外の文字を含む文字ベクトルをASCII順序(Cなど)でソートする方法はありますか? 説明する例:
> v<-c("#1-adfgh3$","-d","!cd3&") > sort(v) [1] "-d" "!cd3&" "#1-adfgh3$"
まだ "!" ASCII 順で「-」の前に来る必要があります。
どうもありがとう。
乾杯、ジョン
ここにアイデアがあります:
asciiSort <- function(vec) { x <- sapply(vec, function(X) { paste0(strtoi(charToRaw(X), base=16), collapse="") }) vec[order(x)] } asciiSort(v) # [1] "!cd3&" "#1-adfgh3$" "-d"