【发布时间】:2015-03-31 08:25:09
【问题描述】:
希望这是有道理的。
我有一串不同长度的 pvalue(由于舍入),其中非常大和小的 pvalue 分别存储为 1.0(some number of 0s corresponding to the length of rounding) 和 0.0(some number of 0s corresponding to the length of rounding)。
我要匹配两组模式:
首先:
"(1.)(string of zeros of any length)"
并将其更改为"> 0.(sting of nines the same length as the string of zeros)"
第二
"(0.)(string of zeros of any length)"
并将其更改为"< 0.(string of zeros the length of the input minus one)1。
所以如果我们有以下输入:
pvals<-c("1.000","1.00","0.00000","0.123","0.6","0.0")
我希望返回:
> expectedOutput
[1] "> 0.999" "> 0.99" "< 0.00001" "0.123" "0.6" "< 0.1"
我一直在尝试使用 gsub,但是我对正则表达式的更复杂的使用知之甚少我不明白如何允许某个字符 (0) 的任何长度,然后如何替换为相同数字的新字符(在 1.0s 的情况下),或该数字减 1(在 0.0s 的情况下)
任何帮助将不胜感激! 谢谢
【问题讨论】:
-
我认为第一个元素的输出是
< 0.999 -
不确定
1.000和1.00之间有什么区别。0.00000、0.0和0之间都没有 -
不,我想要所有以“1”开头的字符串。然后变成“> 0”。”
-
这只是问题的简化。问题是我将收到 0.00000 和 0.0 的输入,我需要保持输入的完整性。
-
@AvainashRaj 啊,我的输入/输出是正确的,但我的规则被颠倒了。很抱歉造成混乱,并感谢您指出这一点。现在已经修好了。