[英]R - Suppressing separator at a single text passage in paste()
When having a paste()
with a given delimiter like in the below example, is it possible to suppress the delimiter at single positions?当有一个带有给定分隔符的paste()
时,如下例所示,是否可以在单个位置抑制分隔符?
The example is part of a ggplot()+labs(subtitle=paste(...))
with whitespace separator:该示例是带有空格分隔符的ggplot()+labs(subtitle=paste(...))
的一部分:
paste("Minimum/maximum number of observations per point:", min(currdataset_S03$nobs), "* /", max(currdataset_S03$nobs), sep = " ")
Now, I'd like to suppress/skip only the whitespace between 7 (=currdataset_S03$nobs) and the asterisk (see red arrow in the image).现在,我想仅抑制/跳过 7 (=currdataset_S03$nobs) 和星号之间的空格(参见图像中的红色箭头)。 But don't know how.但不知道如何。
I'm quite sure that I have seen a quite simple solution some time ago.我很确定我前段时间看到了一个非常简单的解决方案。 But I can't remember it, - or my memory may not serves me right.但我不记得了,或者我的 memory 可能不适合我。
However, I could not find any helpful post so far.但是,到目前为止,我找不到任何有用的帖子。 So, has anybody an idea for me please?那么,有人对我有什么想法吗?
You could solve this using sprintf
.您可以使用sprintf
解决此问题。
sprintf("Minimum/maximum number of observations per point: %s * / %s",
min(currdataset_S03$nobs), max(currdataset_S03$nobs))
# [1] "Minimum/maximum number of observations per point: 7 * / 14"
Data:数据:
currdataset_S03 <- data.frame(nobs=7:14)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.