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

Rの解析に役に立つ記事
スポンサーリンク

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

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

スポンサーリンク

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

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

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

実行コマンド

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

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

###データ例の作成#####
TestData <- sample(1:10000, 5)
#&#20869;&#23481;&#30906;&#35469;
TestData
[1] 2659 1370 3904 6488 7880
########

#&#25968;&#23383;&#12434;&#33521;&#35486;&#34920;&#35352;&#12395;&#22793;&#25563;:english&#12467;&#12510;&#12531;&#12489;
GetEng <- english(TestData)
#&#20869;&#23481;&#30906;&#35469;
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&#12398;&#30906;&#35469;
class(GetEng)
[1] "english"
#&#27083;&#36896;&#12398;&#30906;&#35469;
str(GetEng)
Class 'english'  atomic [1:5] 2659 1370 3904 6488 7880
..- attr(*, "useUK")= logi TRUE
#&#25968;&#23383;&#24773;&#22577;&#12364;&#27531;&#12387;&#12390;&#12356;&#12427;&#12398;&#12391;&#20006;&#12403;&#26367;&#12360;&#12364;&#21487;&#33021;
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 
#&#25991;&#23383;&#12395;&#22793;&#25563;
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をコピーしました