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.
このコード行をsprintf使わずに使用するよりエレガントな方法は何ですか?gsub
sprintf
gsub
gsub(" ","0",sprintf("%2.d", 0:15)) [1] "00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15"
つまり、1 桁の数字の前にゼロが必要です...文字として出力します。
フォーマット文字列でa を使用し0て、スペースの代わりに先行ゼロを埋め込みます。sprintf("%02d", 0:15)
0
sprintf("%02d", 0:15)