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

Formulating a question from a list

Part of working with data is becoming proficient and familiar with inspecting and understanding data frames, lists, and vectors. However, it's important to be able to communicate your findings with reports and plots in a human-readable way across any organization. In the video exercise, you saw how to create sentences from lists with the glue_collapse() function.

In this exercise, you will create a small questionnaire with glue_collapse() that could later be fed to the base R command menu().

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

Intermediate Regular Expressions in R

ดูคอร์ส

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

  • Construct a well formulated question by passing fruits to glue_collapse().
  • Separate the fruits with a comma and a space ", " and an ", or " between the last two elements.

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

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

fruits <- list("Apple", "Banana", "Cherries", "Dragon Fruit")

# Use ", " as a separator and ", or " between the last fruits
question <- glue(
  "Which of these do you prefer: {answers}?",
  answers = glue_collapse(
    ___,
    ___ = "___",
    ___ = "___"
  )
)

# Print question
print(question)
แก้ไขและรันโค้ด