What I want:
To obtain a R dataframe with completion-rate data from all colleges in the US (or all the colleges that have available data in college scorecard datalake).
What I expect:
A data frame in the long format with data from multiple cohorts for each college, something like:
| college_id (if available) | college_name | cohort | completion_rate | median_program_length | average_sat_score |
|---------------------------|----------------------------|--------|-----------------|-----------------------|-------------------|
| 1 | Yale University | 1980 | 0.823 | 4 years | . |
| 1 | Yale University | 1981 | 0.791 | 4 years | . |
| ... | ... | ... | ... | ... | ... |
| 1 | Yale University | 2000 | 0.918 | 4 years | 1421 |
| 1 | Yale University | 2001 | 0.907 | 4 years | 1447 |
| ... | ... | ... | ... | ... | ... |
| 1387 | New College of Springfield | 2000 | 0.231 | 2 years | 704 |
| 1387 | New College of Springfield | 2001 | 0.257 | 2 years | 753 |
What I tried:
I registred in the College Scorecard API website and got my key. I also read and tried to understand the documentation and dictionary, but not quite sure if I understood it well. Then I tried to extract data from the API following some tutorials on the internet, I managed to download some lists of different objects but I cannot manage to extract an R dataframe from them. One of the problems is that these objects apparently do not contain any data.
For example:
library(httr)
library(jsonlite)
completion = GET("https://api.data.gov/ed/collegescorecard/v1/completion?api_key=0eXXXXXXXXXXXXX")
df= fromJSON(rawToChar(completion$content))
print(df)
The result is:
$message
[1] ""
That is, I do not even know If I am being able to download the data that I want. Apparently, the object has no data.
I also tried variants of that request, but it seems that all returned with objects that are lists of lists of empty objects. Or at least I was not able to extract data from it:
completion2 = GET("https://api.data.gov/ed/collegescorecard/v1/schools?fields=completion_rate_4yr_150nt&api_key=0eXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
completion3 = GET("https://api.data.gov/ed/collegescorecard/v1/completion?fields=completion_rate_4yr_150nt&api_key=0eXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
completion4 = GET("https://api.data.gov/ed/collegescorecard/v1/schools?fields=completion&api_key=0eXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
Possible solutions
I have some experience with handling dataframes in R, but I am completely new to accessing APIs with R and also to json files. I read some material on both, but I am still struggling with college scorecard API. I only need help with data extraction from the API and to convert it to an R dataframe. There is no problem if not all data from my example are available in a single request (cohort, completion rate, program length, average SAT score). I can put it together if I have some type of ID variable (like college_id, or unique college names, etc).