Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading JSON data into R

I need to:

  1. Download a parsed file of all the company names provided by http://api.crunchbase.com/v/1/companies.js

  2. Run a query using each company name to download a parsed file of each company's information (e.g. Founded_year, funder company name), using the syntax 'http://api.crunchbase.com/v/1/company/permalink.js'

I would like to parse this data into a spreadsheet or some other format that I can then import into R for analysis.

What is the best format to import this data into R? How can I download the data and organize it into a table-like structure? (e.g. Row = company, columns = profile information like funded_year) (with the ultimate goal of analyzing it in R)

like image 957
user1764260 Avatar asked Oct 22 '12 03:10

user1764260


1 Answers

library(RJSONIO)
library(RCurl)

# grab the data
raw_data <- getURL("http://api.crunchbase.com/v/1/companies.js")
# Then covert from JSON into a list in R
data <- fromJSON(raw_data)
length(data)
[1] 101782
# We can coerce this to a data.frame
 final_data <- do.call(rbind, data)
 # Then write it to a flat csv file
 write.csv(final_data, "final_data.csv")


> head(final_data)
     name                permalink     category_code
[1,] "Wetpaint"          "wetpaint"    "web"        
[2,] "AdventNet"         "adventnet"   "enterprise" 
[3,] "Zoho"              "zoho"        "software"   
[4,] "Digg"              "digg"        "web"        
[5,] "Facebook"          "facebook"    "web"        
[6,] "Photobucket, Inc." "photobucket" "web"        
like image 65
Maiasaura Avatar answered Oct 20 '22 06:10

Maiasaura