How to rename row names in data from Eurostat in R

126 Views Asked by At

I downloaded data from Eurostat to R. In one column I have abbreviated country names, I found how to display full names. But I need to change these row names to show in a different language. I don't care about a specific function, I can do it manually, but how?

Image

2

There are 2 best solutions below

0
On

The countrycode package could help:

#install.packages("countrycode") # if necessary
require("countrycode")


# assuming you data.frame is named df
df$geo <- countrycode(df$geo, origin = 'iso2c', destination = 'un.name.en')

Check out ?countrycode and ?codelist for more encoding options.

0
On

You can set row names with 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"

Or you can add a new column to a data.frame like this

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

Even with another script

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

May look weird because of the UTF-8 encoding

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>

But is good

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