Questions tagged «stringr»

2
dplyr过滤条件以区分Unicode符号及其Unicode表示形式
我正在尝试根据其格式来过滤Symbol列 \uxxxx 这是很容易在视觉上,就是有些模样$,¢,£,和其他人一样\u058f,\u060b,\u07fe。 但是我似乎无法使用stringi/ 弄清楚dplyr library(dplyr) library(stringi) df <- structure(list(Character = c("\\u0024", "\\u00A2", "\\u00A3", "\\u00A4", "\\u00A5", "\\u058F", "\\u060B", "\\u07FE", "\\u07FF", "\\u09F2", "\\u09F3", "\\u09FB", "\\u0AF1", "\\u0BF9", "\\u0E3F", "\\u17DB", "\\u20A0", "\\u20A1", "\\u20A2", "\\u20A3"), Symbol = c("$", "¢", "£", "¤", "¥", "\u058f", "\u060b", "\u07fe", "\u07ff", "৲", "৳", "\u09fb", "\u0af1", "\u0bf9", "฿", "៛", "₠", …
10 r  dplyr  stringr  stringi 

5
正则表达式删除R中的前导零,除非最终(或唯一)字符为零
gsub("(?<![0-9])0+", "", c("005", "0AB", "000", "0"), perl = TRUE) #> [1] "5" "AB" "" "" gsub("(^|[^0-9])0+", "\\1", c("005", "0AB", "000", "0"), perl = TRUE) #> [1] "5" "AB" "" "" 上面的正则表达式来自此SO线程,它说明了如何从R中的字符串中删除所有前导零。由于此正则表达式,“ 000”和“ 0”都转换为“”。相反,我想从字符串中删除所有前导零,但最终字符恰好为零或唯一字符为零的情况除外。 "005" would become "5" "0AB" would become "AB" "000" would become "0" "0" would become "0" 另一个SO线程解释了如何做我想做的事情,但是我认为我在使用R中的解决方案时语法不是很正确。而且我不太了解下面第一和第二解决方案之间的区别(如果他们确实有效)。 …
9 r  regex  string  gsub  stringr 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.