We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b46d3ac commit 7454707Copy full SHA for 7454707
string_manipulation/maskWords.R
@@ -0,0 +1,35 @@
1
+maskWords <- function(text, mask) {
2
+ text_split <- c(unlist(strsplit(text, split = " ")))
3
+
4
+ post_n <- c()
5
+ for (i in text_split) {
6
+ post_n <- c(
7
+ post_n,
8
+ if (i %in% c(
9
+ "birds",
10
+ "BIRDS",
11
+ "Birds",
12
+ "market",
13
+ "Market",
14
+ "MARKET",
15
+ "street",
16
+ "STREET",
17
+ "Street"
18
+ )) {
19
+ tolower(i)
20
+ } else {
21
+ i
22
+ }
23
+ )
24
25
26
+ clean_text <- gsub("\\b(birds|street|market)\\b", mask, post_n)
27
28
+ clean_text <- gsub("\n", "", clean_text)
29
30
+ return(paste(clean_text, collapse = " "))
31
+}
32
33
+post <- "The lady bought groceries from the market, but some of them spilled on the street, and the birds helped themselves."
34
35
+maskWords(text = post,mask = "$$$")
0 commit comments