英文:
RStudio on Windows can't use UTF-8 symbol (approx equal ≈) in data frame
问题
我试图向数据框添加一个"≈"符号。
你可以向数据框添加像"+"和"-"这样的符号。
甚至可以使用以下代码向绘图中添加≈符号
text(x, y, expression("≈"))
但这不适用于数据框,我无法找到一种方法来实现这个。我尝试过使用paste("≈")和一些其他类似的方法,但都不太成功。
例如:
x <- "≈"
print(x)
[1] "˜"
这是一个小例子。唯一的区别是我想要看到那两行变成≈
df <- data.frame(prop = c(0.99, 0.97, 0.5, 0.4, 0.01, 0.02), symbol = NA)
df$symbol <- ifelse(df$prop >= 0.95, "+", "")
df$symbol <- ifelse(df$prop <= 0.05, "-", df$symbol)
df$symbol <- ifelse(df$prop <= 0.95 & df$prop >= 0.05, "≈", df$symbol)
df
看起来像
prop symbol
1 0.99 +
2 0.97 +
3 0.50 approximately equal symbol here
4 0.40 approximately equal symbol here
5 0.01 -
6 0.02 -
我希望得到的是
prop symbol
1 0.99 +
2 0.97 +
3 0.50 ≈
4 0.40 ≈
5 0.01 -
6 0.02 -
英文:
I am trying to add a "≈" to a data frame.
You can add symbols like "+" and "-" to a data frame.
You can even add the ≈ symbol to a plot using
text(x,y, expression(""%~~%""))
but this won't work inside a data frame and I cannot find a way to do this.
I have tried just pasting a ≈ using paste("≈") and a few other equally feeble things.
For example:
x <- "≈"
print(x)
[1] "˜"
Here is a small example. The only difference that I would like to see is those middle two rows become ≈
df<-data.frame(prop=c(0.99, 0.97, 0.5,0.4,0.01, 0.02), symbol=NA)
df$symbol<-ifelse(df$prop>=0.95, "+","")
df$symbol<-ifelse(df$prop<=0.05, "-",df$symbol)
df$symbol<-ifelse(df$prop<=0.95 & df$prop>=0.05, "approximately equal symbol here",df$symbol)
df`
looks like
prop symbol
1 0.99 +
2 0.97 +
3 0.50 approximately equal symbol here
4 0.40 approximately equal symbol here
5 0.01 -
6 0.02 - -
What I would like
prop symbol
1 0.99 +
2 0.97 +
3 0.50 ≈
4 0.40 ≈
5 0.01 -
6 0.02 -
答案1
得分: 0
根据评论
Sys.setlocale(locale='.utf8') 或 Sys.setlocale(locale='.65001')
英文:
as per the comments
Sys.setlocale(locale='.utf8') or Sys.setlocale(locale='.65001')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论