不知道你的“特殊字符” ......我要使用的条件是什么:"[o]{2}|[y]$"
或基本术语
如果单词包含两个“O公司“或以'y'结尾:乘以3;如果不是3
使用tm
包为stopwords
和package::dplyr
# Created some data to mimic yours
var_df <- data.frame(word = tm::stopwords(),
stringsAsFactors = FALSE) %>% mutate(
positive.polarity = sample(0:1, nrow(.), TRUE)) %>% mutate(
negative.polarity = ifelse(positive.polarity == 1, 0, 1)
) %>%
# Applying the condition and evaluating the variable formula if met
mutate(
positive.ponderate.polarity = ifelse(
grepl("[o]{2}|[y]$", word),
positive.polarity * 3,
positive.polarity/3)
)
tail(var_df, 10)
word positive.polarity negative.polarity positive.ponderate.polarity
165 no 0 1 0.0000000
166 nor 0 1 0.0000000
167 not 1 0 0.3333333
168 only 1 0 3.0000000
169 own 1 0 0.3333333
170 same 1 0 0.3333333
171 so 0 1 0.0000000
172 than 1 0 0.3333333
173 too 1 0 3.0000000
174 very 1 0 3.0000000
划分可以使用'ifelse'。顺便说一下,特殊字符是什么? – akrun