R 在 Windows 平台 Rstudio 上的 data.frame 中打印 UTF-8 代码



当数据框中有 UTF-8 字符时,它将无法正确显示。

例如,以下是正确的:

> "U6731"
[1] "朱"

但是当我把它放在数据框中并打印出来时,它是:

> data.frame(x="U6731")
x
1 <U+6731>

因此,我认为这与编码问题无关。

有没有直接的方法打印而不是<U+6731>.

我必须在公司使用Windows,所以使用Linux对我来说可能不可行。

语料库有一个针对此错误的解决方法。要么这样做:

library(corpus)
df <- data.frame(x = "U6731")
print.corpus_frame(df)

或者这样做:

class(df) <- c("corpus_frame", "data.frame")
df

你是对的,在调用整个数据帧时,它会给出 UTF-8 字符的代码:

> data.frame(x="U6731")
x
1 <U+6731>

但是如果你调用列或行,它会很好地打印:

# through the column name
> data.frame(x="U6731")$x
[1] 朱
Levels: 朱
# through the column index
> data.frame(x="U6731")[,1]
[1] 朱
Levels: 朱
# through the row index
> data.frame(x="U6731")[1,]
[1] 朱
Levels: 朱

不确定这是否有帮助。您能否更具体地说明为什么以及如何准确输出这些字符?

最新更新