เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Replacing missing data

Rather than deleting the missing interest rates, you may want to replace them instead. The object na_index, which contains the index of the observations with missing interest rates is still loaded in your workspace.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Credit Risk Modeling in R

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Create an object called median_ir, containing the median of the interest rates in loan_data using the median() function. Don't forget to include the argument na.rm = TRUE.
  • In the new data set loan_data_replace, replace all the missing instances in the indices stored in object na_index with the median of all the interest rates, median_ir.
  • Have a look at the variable int_rate in the new data set using summary() to make sure that the NAs are gone.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Compute the median of int_rate


# Make copy of loan_data
loan_data_replace <- loan_data

# Replace missing interest rates with median
loan_data_replace$int_rate[___] <- ___

# Check if the NAs are gone
แก้ไขและรันโค้ด