RStudio在Windows上无法在数据框中使用UTF-8符号(近似等于≈)。

huangapple go评论67阅读模式
英文:

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.504 0.405 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(&quot;&quot;%~~%&quot;&quot;)) 

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 &lt;- &quot;≈&quot;
print(x)

[1] "˜"

Here is a small example. The only difference that I would like to see is those middle two rows become ≈

df&lt;-data.frame(prop=c(0.99, 0.97, 0.5,0.4,0.01, 0.02), symbol=NA)

df$symbol&lt;-ifelse(df$prop&gt;=0.95, &quot;+&quot;,&quot;&quot;)
df$symbol&lt;-ifelse(df$prop&lt;=0.05, &quot;-&quot;,df$symbol)
df$symbol&lt;-ifelse(df$prop&lt;=0.95 &amp; df$prop&gt;=0.05, &quot;approximately equal symbol here&quot;,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')

huangapple
  • 本文由 发表于 2023年2月24日 00:26:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75547613.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定