Rでお遊び:数字を英語に変換します「english」パッケージ

Rの解析に役に立つ記事

1をoneというように数字を英語に変換するパッケージの紹介です。使う機会が少ないかもしれませんが面白いので紹介します。

パッケージバージョンは1.1。windows 10のR version 3.3.2で動作を確認しています。

スポンサーリンク
スポンサーリンク

パッケージのインストール

下記コマンドを実行してください。

#パッケージのインストール
install.packages("english")

実行コマンド

詳細はコマンド、パッケージのヘルプを確認してください。

#パッケージの読み込み
library("english")

###データ例の作成#####
TestData <- sample(1:10000, 5)
#内容確認
TestData
[1] 2659 1370 3904 6488 7880
########

#数字を英語表記に変換:englishコマンド
GetEng <- english(TestData)
#内容確認
GetEng
[1] two thousand six hundred and fifty nine    one thousand three hundred and seventy    
[3] three thousand nine hundred and four       six thousand four hundred and eighty eight
[5] seven thousand eight hundred and eighty
#classの確認
class(GetEng)
[1] "english"
#構造の確認
str(GetEng)
Class 'english'  atomic [1:5] 2659 1370 3904 6488 7880
..- attr(*, "useUK")= logi TRUE
#数字情報が残っているので並び替えが可能
sort(GetEng)
[1] one thousand three hundred and seventy     two thousand six hundred and fifty nine   
[3] three thousand nine hundred and four       six thousand four hundred and eighty eight
[5] seven thousand eight hundred and eighty 
#文字に変換
as.character(GetEng)
[1] "two thousand six hundred and fifty nine"   
[2] "one thousand three hundred and seventy"    
[3] "three thousand nine hundred and four"      
[4] "six thousand four hundred and eighty eight"
[5] "seven thousand eight hundred and eighty"

あなたの解析がとっても楽になりますように!!

タイトルとURLをコピーしました