如何使用R的sprintf在END中创建填充空白的固定宽度的字符串? [英] How to use R's sprintf to create fixed width strings with fill whitespace at the END?

查看:208
本文介绍了如何使用R的sprintf在END中创建填充空白的固定宽度的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有字符串的矢量,并希望创建一个固定的字符串。较短的字符串应填充空白。例如:

I have vector of strings and want to create a fixed with string out of that. Shorter strings should be filled up with white spaces. E.g.:

c("fjdlksa01dada","rau","sjklf")
sprintf("%8s")
# returns
[1] "fjdlksa01dada" "     rau"      "   sjklf"

但是我怎样才能得到额外的空白字符串的结束?

But how can I get the additional whitespace at the END of the string?

请注意,我听说从 gdata的write.fwf package这真的很好,但在这种情况下帮不了多少,因为我需要为过时的旧程序编写非常具体的非标准格式。

Note that I heard of write.fwf from the gdata package which is really nice but doesn't help much in this case, because I need to write a very specific non-standard format for an outdated old program.

推荐答案

这篇关于如何使用R的sprintf在END中创建填充空白的固定宽度的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆