stringr

    8热度

    2回答

    相关问题here。 所以我有一个货币值包含美元符号和逗号的字符向量。但是,我想尝试在同一步骤中删除逗号和美元符号。 这消除了美元符号= d = c("$0.00", "$10,598.90", "$13,082.47") gsub('\\$', '', d) 这将删除逗号= library(stringr) str_replace_all(c("10,0","tat,y"), fixed(

    12热度

    1回答

    我试图替换两个“st”。和“ste。”与“st”。好像下面应该工作,但它并不: require("stringr") county <- c("st. landry", "ste. geneveve", "st. louis") str_replace_all(county, c("st\\.", "ste\\."), "st")

    7热度

    2回答

    我有一个字符串,它是混合字母和数字: "The sample is 22mg" 我想分裂字符串,其中一个号码后面紧接着信是这样的: "The sample is 22 mg" 我已经试过这样: gsub('[0-9]+[[aA-zZ]]', '[0-9]+ [[aA-zZ]]', 'This is a test 22mg') ,但我没有得到期望的结果。 有什么建议吗?

    1热度

    1回答

    我试图通过使用下面的代码找到(然后提取)重复的短语。我需要以“大约”开始并以“关闭”结尾的短语。 例如“总资产约为1.629亿$,并在总存款$ 144.5万元关闭” str_locate(x,"(\b[Aa]pproximately\b)(.*)(\b[Cc]losed\b)") str_extract(x,"(\b[Aa]pproximately\b)(.*)(\b[Cc]losed\b)")

    3热度

    2回答

    不幸的是我吸食正则表达式。如果我有这样的路径: /long/path/to/file,我只需要提取file。 如果有人提供file/我只需要file。 如果有人提供/file/,我仍然只需要file。 我一直在使用stringr作为一个拐杖的功能,但这似乎是直接向上grep领土。请帮助?

    1热度

    4回答

    我有一个由单词组成的列表。 > head(splitWords2) [[1]] [1] "Some" "additional" "information" "that" "we" "would" "need" "to" "replicate" "the" [11] "experiment" "is" "how" "much" "vinegar" "should

    5热度

    1回答

    我想清除包含转义引号的字符串。我想删除转义引号字符串的结尾和开头,但保留字符串中的所有qoutation标记完整。我想到的是以下内容。 library(stringr) s1 <- "\"He said:\"Hello\" - some word\"" str_replace_all(s1, "(^\\\")|(\\\"$)", "") > [1] "He said:\"Hello\" -