Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么str_替换R中的字符串?_R_String_Str Replace - Fatal编程技术网

为什么str_替换R中的字符串?

为什么str_替换R中的字符串?,r,string,str-replace,R,String,Str Replace,我确实有一个数据框,需要在其中编辑疾病名称。每种疾病都有几行与其相关。出于某种原因,当我使用str\u replace\u all时,在两种情况下都不会发生置换(“周围神经病变(不包括颅神经和腕管综合征)”,“静脉血栓栓塞性疾病(不包括PE)”。输出中没有警告或错误消息,因此我无法找出问题所在。有人有什么想法吗 codelists <- data.frame(Disease = sample(c("Peripheral neuropathies (excluding crania

我确实有一个数据框,需要在其中编辑疾病名称。每种疾病都有几行与其相关。出于某种原因,当我使用str\u replace\u all时,在两种情况下都不会发生置换
(“周围神经病变(不包括颅神经和腕管综合征)”,“静脉血栓栓塞性疾病(不包括PE)”
。输出中没有警告或错误消息,因此我无法找出问题所在。有人有什么想法吗

codelists <- data.frame(Disease = sample(c("Peripheral neuropathies (excluding cranial nerve and carpal tunnel syndromes)", "Primary Malignancy_Brain, Other CNS and Intracranial", "Venous thromboembolic disease (Excl PE)"), 15, replace = T), Codes = 1:15)

## Sort the dataframe according to Disease
codelists <- codelists[order(codelists$Disease), ]

library(stringr)
codelists$Disease2 <- str_replace_all(codelists$Disease, c("Peripheral neuropathies (excluding cranial nerve and carpal tunnel syndromes)" = "Non-diabetic peripheral neuropathies (excluding cranial nerves and carpal tunnel syndrome)", "Primary Malignancy_Brain, Other CNS and Intracranial" = "Primary malignancy brain, other CNS and intracranial", "Venous thromboembolic disease (Excl PE)" = "Venous thromboembolism"))

code列表在
regex
chaarcters类
*
有特殊含义。
str\u replace\u all
默认使用regex替换。由于您希望匹配
(不包括颅神经和腕管综合征)
等词,请准确使用
固定的

library(stringr)

codelists$Disease2 <- str_replace_all(codelists$Disease, fixed(c("Peripheral neuropathies (excluding cranial nerve and carpal tunnel syndromes)" = "Non-diabetic peripheral neuropathies (excluding cranial nerves and carpal tunnel syndrome)", "Primary Malignancy_Brain, Other CNS and Intracranial" = "Primary malignancy brain, other CNS and intracranial", "Venous thromboembolic disease (Excl PE)" = "Venous thromboembolism")))
库(stringr)
代码列表$Disease2