在 data.frame 变量的值中插入特定的 unicode 符号 [英] Insert specific unicode symbols inside values of data.frame variable

查看:28
本文介绍了在 data.frame 变量的值中插入特定的 unicode 符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 data.frame 中,我想添加两个变量A"和B",它们的值分别包含一个带有 i 下标的 n 和一个n 带有 s 下标.
到目前为止,我已经了解,不可能为变量的值指定表达式,因此要添加特殊字符,必须使用 unicode 符号.这些 un​​icode 中的一些在 R 中工作,例如希腊字母mu",用 unicode \U00B5 或数字下标标识,如您在 R 控制台中的这个 reprex 中看到的:

In my data.frame I would like to add two variables, "A" and "B", whose values contain respectively an n with the i subscript and an n with the s subscript.
As I have understood so far, it's not possible to specify an expression for the values of a variable, and hence to add special characters it's necessary to use unicode symbols. Some of this unicodes work in R, as for example the greek letter "mu", identified with the unicode \U00B5, or numeric subscripts, as you can see in this reprex in your R console:

x <- data.frame("A" = c("\U00B5"),
                "B" = c("B\U2082"))

print(x)

如果我决定将这个变量放在一个 ggplot() 对象中,这些 un​​icode 也可以工作,因为我将在轴文本或刻面上显示正确的符号(例如mu").
问题是,当我对 i (unicode: \U1D62) 和 s (unicode: \u209B) 的下标执行相同操作时,R 无法识别 unicode并在变量名内打印整个字符串.

These unicodes work also if I decide to put this variable in a ggplot() object, because I will display the correct symbol ("mu" for example) on the axis text or the facets.
The problem is that when I do the same for the subscripts of i (unicode: \U1D62) and s (unicode: \u209B), R doesn't recognise the unicode and prints the whole string inside the variable name.

你知道我如何解决这个问题吗?这个 unicode 是否适用于每个操作系统?

Do you know how I can resolve this issue and if this unicode works on every operating system?

谢谢

推荐答案

如果您使用的是最近更新为 2018 年 4 月更新的 Windows 10:使用 Windows 键 + '.'(例如,在文本编辑器中将 Windows 键加句点放在一起).这会调出 Microsoft 表情符号键盘.为您的脚本选择希腊字母变量.R 控制台不会直接接受希腊字母作为变量,而只会接受来自编辑器脚本的希腊字母.一些希腊字母不能翻译成英语(如µ"或ß".)您可以从 ls() 输出粘贴和复制它们以访问.您也可以将一些数学符号用于变量名称.但是,我不能让它与 source() 一起使用.那一定是文本编码问题.

If you are on Windows 10 recently updated with as of April 2018 Update: Use the Windows key + '.' (e.g. hold together Windows Key plus period) in your text editor. This brings up Microsoft Emoji keyboard. Select the Greek letters variable for your script. The R Console will not accept the Greek letters as variables directly but only the from the editor script. Some of the Greek letters don't translate to English (like "µ" or "ß".) You can paste and copy them from ls() output to access. You may be able to use some math symbols as well for variable names. I can't however, get this to work with source(). That must be a text encoding problem.

这篇关于在 data.frame 变量的值中插入特定的 unicode 符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆