Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function named month _ convert ( x , from _ lang, to _ lang ) that will convert month names from one language

Write a function named month_convert(x, from_lang, to_lang) that will convert month names from one
language to another. The function will accept three arguments: x, which is a factor with month information;
the language from which we are translating from_lang; and the language to which we are translating to_lang.
I have uploaded a file called month_names.txt on Canvas which has the month names in several European
languages. Use
2
month_names <- read.delim("month_names.txt", encoding="UTF-8", row.names=1)
to import the file.
Then apply your conversion function, for example:
x <- factor(c("March","March","February","June"))
month_convert(x, "English", "Spanish")
## [1] marzo marzo febrero junio
## Levels: febrero junio marzo
If the input contains a value that is not a real month, then it will be replaced with NA. Any values that are
not real months should have the corresponding levels removed as well.
x <- factor(c("March","March","February","June","Jaly"))
month_convert(x, "English", "Spanish")
## [1] marzo marzo febrero junio
## Levels: febrero junio marzo
The order of the levels should remain the same before and after conversion between languages (they should
not be realphabetized).
x <- factor(c("August", "April", "December", "April"))
x
## [1] August April December April
## Levels: April August December
month_convert(x, "English", "Italian")
## [1] agosto aprile dicembre aprile
## Levels: aprile agosto dicembre
--- month_names file:
language m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12
English January February March April May June July August September October November December
Czech leden nor bezen duben kvten erven ervenec srpen zjen listopad prosinec
Danish januar februar marts april maj juni juli august september oktober november december
Dutch januari februari maart april mei juni juli augustus september oktober november december
Finnish tammikuu helmikuu maaliskuu huhtikuu toukokuu keskuu heinkuu elokuu syyskuu lokakuu marraskuu joulukuu
French janvier fvrier mars avril mai juin juillet aot septembre octobre novembre dcembre
German Januar Februar Mrz April Mai Juni Juli August September Oktober November Dezember
Hungarian janur februr mrcius prilis mjus jnius jlius augusztus szeptember oktber november december
Icelandic janar febrar mars aprl ma jn jlgst september oktber nvember desember
Italian gennaio febbraio marzo aprile maggio giugno luglio agosto settembre ottobre novembre dicembre
Norwegian januar februar mars april mai juni juli august september oktober november desember
Polish stycze luty marzec kwiecie maj czerwiec lipiec sierpie wrzesie padziernik listopad grudzie
Portuguese janeiro fevereiro maro abril maio junho julho agosto setembro outubro novembro dezembro
Spanish enero febrero marzo abril mayo junio julio agosto septiembre octubre noviembre diciembre
Swedish januari februari mars april maj juni juli augusti september oktober november december
Turkish ocak ubat mart nisan mayis haziran temmuz austos eyll ekim kasm aralk
--- PLease solve in R! willing to like

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Management Foundations A Pacific Rim Focus

Authors: Kathryn Bartol, Margaret Tein, Graham Matthews, Bishnu Sharma, Brenda Scott Ladd

3rd Edition

978-0070284944, 0070284946

Students also viewed these Accounting questions