Hi! I am new to R. I am a newbie to data analytics. I am avid to learn R, particularly the tidyverse for a career change.

I have a questions. I am practicing R. I tried to collect a data from a free API to learn how to collect data. So, the data I collected is nested list or a list as you can see in the above image. Why is it when I used the "as.data.frame()", the output gives the nested list of observations and 7 variables? On the otherhand, when I used the "as_tibble", the output provide all of the observations/rows and ONLY 2 VARIABLES?

What should I use in the real world as a data analyst relating to image I have attached? Why is it "as.data.frame" has 7 variables from the list while the "as_tibble" gives 2 variables. At the same time, it gives me error and warning message when I used "skim_without_charts" in "as_tibble". Can someone explain it to me and what function should I use whenever a data is a form of list to be usable for a data analysis process. Thank you!

first of all, the JSON heirarchy you got seems relatively simple, its a data.frame and an ok status message.
The most straightforward way for you to consume that is almost certainly, to drop/ignore the ok status , and just take the data part.

this is df$data following your original code.

Also your question about as_tibble vs as.data.frame, I find is a bit hard to answer as you muddied the waters wiht additional do.call cbind command. so to compare like for like I would think you would be doing

(example_input <- list(
  data=data.frame(a=1:2,
                  b=3:4),
  status="ok"
))

(df_clean_astib_plain <- as_tibble(example_input))
(df_clean_astib_bind <- as_tibble(do.call(cbind,example_input)))
(df_clean_plain <- as.data.frame(example_input))
(df_clean_bind <- as.data.frame(do.call(cbind,example_input)))

These are broadly the same barring some differing treatment in constructing appropriate column names

1 Like

I really appreciated your effort in replying to my question. I kept on searching through the google, stackoverflow, and this posit community. Because I am confused on how can I turn the collected data to a usable dataset. I kept on reading different articles. There's too many discussion and still keep on asking myself what should I do, what should I type to make it usable. Then, there you are. You completed the pieces of the puzzle. You answered my question.

So, what I really needed was just the "df$data" to make it a usable dataset. I was confused because it's a LIST with 2 variables named "data" and "status". There's $status: chr "ok". What and why there is a variable named "status" having a value of "ok". Now, I understand how to make it usable. I really appreciate it! You saved me from hours of thinking, searching, reading different articles and watching videos that do not explain properly what and why these functions is used. Thank you again! :+1:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.