Skip to content

Week 4 Quiz:Getting and Cleaning Data(Data Science Specialization):Answers2025

Question 1

Apply strsplit() to split the column names on "wgtp". What is the value of element 123 of the resulting list?

"15"
"w" "15"
"wgtp" "15"
"" "15"

Explanation: Splitting the name that contains "wgtp15" on "wgtp" produces two pieces: an empty string before the match and "15" after it — i.e. "" and "15".


Question 2

Load the GDP data, remove commas from the GDP numbers (millions of dollars), convert to numeric and average them. What is the average?

❌ 387854.4
❌ 381615.4
❌ 381668.9
377652.4

Explanation: After reading the relevant 190 ranked country rows, removing commas from the GDP column, converting to numeric and taking the mean, the average GDP (in the units provided) is 377652.4.


Question 3

Which regex and count find country names that begin with “United”? How many countries begin with United?

grep("*United",countryNames), 2
grep("*United",countryNames), 5
grep("United$",countryNames), 3
grep("^United",countryNames), 3

Explanation: ^United matches names that start with “United”. There are three country names that begin with “United”.


Question 4

Match GDP and education data by country code. Of countries for which fiscal year end is available, how many end in June?

❌ 13? (no)
13
❌ 31
❌ 15

Explanation: After merging the GDP and EDSTATS datasets on the country shortcode and filtering to non-missing fiscal year entries, counting those whose fiscal year string ends with "June" yields 13 countries.


Question 5

Using quantmod::getSymbols("AMZN") and sampleTimes = index(amzn): How many values were collected in 2012? How many on Mondays in 2012?

❌ 252, 50
250, 47
❌ 251, 47
❌ 250, 51

Explanation: The AMZN time series for 2012 contains 250 trading-day entries; among those dates 47 are Mondays.


🧾 Summary Table

Q# ✅ Correct Answer Key Concept
1 "" "15" strsplit() splitting yields empty prefix + "15"
2 377652.4 Clean commas → numeric → mean of GDP column
3 grep("^United",countryNames), 3 Regex ^ anchors start-of-string; 3 matches
4 13 Merge GDP & education; count fiscal-year strings ending with June
5 250, 47 Time-series indexing; count dates in 2012 and Mondays