首页 > 解决方案 > 如何在R中重命名来自欧盟统计局的数据中的行名

问题描述

我将数据从 Eurostat 下载到 R。在一列中,我使用缩写的国家名称,我发现了如何显示全名。但我需要更改这些行名以使用不同的语言显示。我不关心特定的功能,我可以手动完成,但是如何?

在此处输入图像描述

标签: rrowname

解决方案


您可以使用rownames

d <- data.frame(x=1:3, y = letters[1:3])
rownames(d)
#[1] "1" "2" "3"
rownames(d) = c("the", "fox", "jumps")
rownames(d)
#[1] "the"   "fox"   "jumps"

或者您可以像这样向 data.frame 添加新列

d$french <- c("le", "renard", "saute")
d
#      x y french
#the   1 a     le
#fox   2 b renard
#jumps 3 c  saute

即使使用另一个脚本

d$tajik <- c("рӯбоҳ", "ҷаҳиш", "мекунад")

由于 UTF-8 编码,可能看起来很奇怪

d
#      x y french                                                    tajik
#the   1 a     le                 <U+0440><U+04EF><U+0431><U+043E><U+04B3>
#fox   2 b renard                 <U+04B7><U+0430><U+04B3><U+0438><U+0448>
#jumps 3 c  saute <U+043C><U+0435><U+043A><U+0443><U+043D><U+0430><U+0434>

不过很好

d$tajik
#[1] "рӯбоҳ"   "ҷаҳиш"   "мекунад"
 

推荐阅读