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

JSON practice (2)

We prepared two more JSON strings in the sample code. Can you change them and call jsonlite's fromJSON() function on them, similar to the previous exercise?

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

Intermediate Importing Data in R

ดูคอร์ส

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

  • Remove characters from json1 to build a 2 by 2 matrix containing only 1, 2, 3 and 4. Call fromJSON() on json1.
  • Add characters to json2 such that the data frame in which the json is converted contains an additional observation in the last row. For this observations, a equals 5 and b equals 6. Call fromJSON() one last time, on json2.

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

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

# jsonlite is already loaded

# Challenge 1
json1 <- '[[1, 2], [3, 4], [5, 6]]'


# Challenge 2
json2 <- '[{"a": 1, "b": 2}, {"a": 3, "b": 4}]'
แก้ไขและรันโค้ด