R studio, need help with #3 in creating the Tourism_Type
colum.
Part 1 Tasks 1. If necessary, set you working directory. Read the tourism table and create the cleaned_tourism table. 2. Remove the columns _1995 through _2013. 3. Create the Country Name and Tourism_Type columns from values in the Country column. Valid values for Tourism_Type are Inbound tourism and Outbound tourism. 4. Run your code and view the cleaned_tourism table so far. Remove rows that contain only the country name and tourism type information. Hints 1. Use set.wd() to redefine your working directory and use this directory to create your output files for this case study. 2. Consider using the dplyr::select function to keep only the columns you want. 3. Look at the tourism table and notice that there is a value in column A when there is a country name in the Country column. Use a case_when() statement to test for this and then assign the value in Country to country_Name. In the output table, the value of Country_Name should be included in every row. You can also use IF-THEN logic to create the values for Tourism_Type. You should explicitly define the column and write the value to every row in the output data. 4. Run your code. In the output table, notice that there are rows that have the same values in the Country/Country_Name columns and in the Country/Tourism_Type columns. These are rows that do not contain any other data. Use a filter () statement to eliminate these rows.
A COUNTRY 826 UNITED KINGDOM Inbound tourism Arrivals Thousands Tourism expenditure in the country - US$ Mn Travel - US$ Mn Passenger transport - US$ Mn Outbound tourism Departures Thousands Tourism expenditure in other countries - US$ Mn Travel - US$ Mn Passenger transport - US$ Mn Series TF IMF IMF IMF TF IMF IMF IMF 1995 21,719 27,577 20,487 7,090 41,345 30,749 24,926 5,823 1996 22,936 29,181 21,389 7,792 42,050 32,298 25,962 6,336 1997 23,215 30,483 22,586 7,897 45,957 35,954 28,529 7,425 1998 23,710 31,658 23,689 7,969 50,872 41,458 33,452 8,006 1999 23,341 30,807 22,716 8,091 53,881 45,536 37,034 8,502 2000 23,212 29,978 21,769 8,209 56,837 47,009 38,262 8,747 2001 20,982 26,137 18,864 7,273 58,281 46,410 37,931 8,479 2002 22,307 27,819 20,549 7,270 59,377 51,125 41,744 9,381 2003 22,787 30,736 22,668 8,068 61,424 58,627 47,853 10,774
A COUNTRY COUNTRY Series Series _2014 2014 COUNTRY_NAME A 1 NA Inbound tourism AFGHANISTAN 2 NA AFGHANISTAN 3 NA 91 AFGHANISTAN 4 NA 82 AFGHANISTAN 5 NA 9 AFGHANISTAN 6 NA AFGHANISTAN 7 NA AFGHANISTAN 8 NA 122 AFGHANISTAN Arrivals - Thousands Tourism expenditure in the country - US$ Mn IMF Travel - US$ Mn IMF Passenger transport - USS Mn IMF Outbound tourism Departures - Thousands Tourism expenditure in other countries - US$ Mn IMF Travel - US$ Mn Passenger transport - USS Mn Inbound tourism Arrivals - Thousands VF Arrivals - Thousands Arrivals - Thousands THS Tourism expenditure in the country - US$ Mn 9 NA IMF 111 AFGHANISTAN 10 NA IMF 11 AFGHANISTAN 11 NA ALBANIA 12 NA 3673 ALBANIA 13 NA TF 3341 ALBANIA 14 NA 161 ALBANIA 15 NA IMF 1849 ALBANIA 16 NA Travel - US$ Mn IMF 1700 ALBANIA 17 NA Passenger transport - US$ Mn IMF 149 ALBANIA 18 NA Outbound tourism ALBANIA
3 9 NEHHHHH #Part 1 #1. Read the tourism table and create the cleaned_tourism table 5 Tour <- read_rds ("C:/Users/gerar/Downloads/tourism.rds") 6 Continent <- read_rds ("C:/Users/gerar/Downloads/country_info.rds") 7 head (Tour) 8 #2. Remove the columns 1995 through _2013 10 df <- select (Tour, CA, COUNTRY, Series, "_2014")) 11 12 df 13 14 #3. create the country Name and Tourism_Type columns 15 df <- df %>% mutate(COUNTRY_NAME = ifelse(!is.na(A), COUNTRY, NA)) %>% 16 fill(COUNTRY_NAME) %>% 17 filter (is.na(A)) 18 19 head(df) 20 im ON 00 O ONMO00 OC
R studio, need help with #3 in creating the Tourism_Type colum.
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
R studio, need help with #3 in creating the Tourism_Type colum.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!