paste() 用标签折叠 [英] paste() collapse with tabs

查看:34
本文介绍了paste() 用标签折叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用制表符连接字符串?我想生成一个制表符分隔的文件,但使用

Is there a way to concatenate strings with tabs? I want to generate a tab separated file but using

paste(c("blah","blah"), collapse="\t")

给予

"blah\tblah"

使用

paste(c("blah","blah"), sep='\t')

给予

"blah" "blah"

我想要一些效果

"blah    blah"

其中条目是一个字符串,单词由制表符分隔.

where the entries are one string with the words separated by tabs.

推荐答案

你不需要花时间在这上面绞尽脑汁.只需在 collapse 中插入四个空格.

You don't need to spend time racking your brain on this. Just stick four spaces in collapse.

paste(c("blah","blah"), collapse = "    ")
# [1] "blah    blah"

顺便说一句,以您已有的方式写入文件会很好.如果我们这样做

By the way, it would be fine to write to file the way you already have it. If we do

writeLines(paste(c("blah", "blah"), collapse = "\t"), "blah.txt")

文件blah.txt看起来像这样

blah    blah

事实上,您可以将其简化为将 paste() 排除在等式之外.

In fact, you could simplify it to take paste() out of the equation.

writeLines(c("blah", "blah"), sep = "\t")
# blah    blah  

这篇关于paste() 用标签折叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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