Can anyone help me understand the following behavior? I want to replace the letter 'X' in âthe string â 'text X' with 'â¥' (\u226 â5 ). The output from gsub is not what I expect. It gives: "text ââ°Â¥".
Now, suppose I want to replace the character 'â¤' in â the stringâ 'text â¤' with 'â¥'. Then, gsub gives the expected, desired output. âWhat am I missing? Thanks for any insight. -tgs Minimal Working Example: string1 <- "text X"; string1 new_string1 <- gsub("X","\u2265",string1); new_string1 string2 <- "text \u2264"; string2 new_string2 <- gsub("\u2264","\u2265",string2); new_string2 charToRaw(new_string1) charToRaw(new_string2) sessionInfo() ## OUTPUT > string1 <- "text X"; string1 [1] "text X" > new_string1 <- gsub("X","\u2265",string1); new_string1 [1] "text ââ°Â¥" > string2 <- "text \u2264"; string2 [1] "text â¤" > new_string2 <- gsub("\u2264","\u2265",string2); new_string2 [1] "text â¥" > charToRaw(new_string1) [1] 74 65 78 74 20 e2 89 a5 > charToRaw(new_string2) [1] 74 65 78 74 20 e2 89 a5 > sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_3.0.2 [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.