r - 如何在R中重命名来自欧盟统计局的数据中的行名
问题描述
我将数据从 Eurostat 下载到 R。在一列中,我使用缩写的国家名称,我发现了如何显示全名。但我需要更改这些行名以使用不同的语言显示。我不关心特定的功能,我可以手动完成,但是如何?
解决方案
您可以使用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] "рӯбоҳ" "ҷаҳиш" "мекунад"
推荐阅读
- javascript - 闪屏视频科尔多瓦
- xquery - eXist - 加载 XSLT 集合() - URIResolver 引发的异常
- typescript - X | 在不检查箭头函数的情况下,未定义缩小到从不
- jquery - jQuery Smart Wizard 移除自动滚动
- python - 在python中删除多维数组中的重复值
- sql - SQL Server:获取其他列都具有相同值的列值
- maven - exec-maven-plugin 无法正确使用参数
- r - 如何从R中的文件夹中保存csv中的所有文件?
- javascript - 搜索公共子字符串
- angular - Angular CLI 与后端 api 在同一个项目中