{"id":343,"date":"2013-11-25T14:38:04","date_gmt":"2013-11-25T19:38:04","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=343"},"modified":"2013-11-25T14:38:04","modified_gmt":"2013-11-25T19:38:04","slug":"importing-data-into-r-from-different-sources","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2013\/11\/25\/importing-data-into-r-from-different-sources\/","title":{"rendered":"Importing Data Into R from Different Sources"},"content":{"rendered":"<p>I have found that I get data from many different sources. \u00a0These sources range from simple .csv files to more complex relational databases, to structure XML or JSON files. \u00a0I have compiled the different approaches that one can use to easily access these datasets.<\/p>\n<p><strong>Local Column Delimited Files<\/strong><\/p>\n<p>This is probably the most common and easiest approach to load data into R. \u00a0It simply requires one line to do everything that is needed to set up the data. \u00a0Then a couple additional lines to tidy up the dataset.<\/p>\n<div>\n<div id=\"highlighter_109631\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<\/td>\n<td>\n<div>\n<div><code>file &lt;- <\/code><code>\"c:\\\\my_folder\\\\my_file.txt\"<\/code><\/div>\n<div><code>raw_data &lt;- read.csv(file, sep=<\/code><code>\",\"<\/code><code>); \u00a0##<\/code><code>'sep'<\/code> <code>can be a number of options including \\t for tab delimited<\/code><\/div>\n<div><code>names(raw_data) &lt;- c(<\/code><code>\"VAR1\"<\/code><code>,<\/code><code>\"VAR2\"<\/code><code>,<\/code><code>\"RESPONSE1\"<\/code><code>)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Text File From the Internet<\/strong><\/p>\n<p>I find this very useful when I need to get datasets from a Web site. \u00a0This is particularly useful if I need to rerun the script and the Web site continually updates their data. \u00a0This save me from having to download the dataset into a csv file each time I need to run an update. \u00a0In this example I use one of my favorite data sources which comes from the National Data Buoy Center. \u00a0This example pulls data from a buoy (buoy #44025) off the coast of New Jersey. \u00a0Conveniently you can use the same read.csv() function that you would use if read the file from you own computer. \u00a0You simply replace the file location with the URL of the data.<\/p>\n<div>\n<div id=\"highlighter_662278\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<\/td>\n<td>\n<div>\n<div><code>file &lt;- <\/code><code>\"&lt;a href=\"<\/code><code><a href=\"http:\/\/www.ndbc.noaa.gov\/view_text_file.php?filename=\">http:\/\/www.ndbc.noaa.gov\/view_text_file.php?filename=<\/a><\/code><code>44025<\/code><code>h<\/code><code>2011<\/code><code>.txt.gz&amp;dir=data\/historical\/stdmet\/<\/code><code>\"&gt;<a href=\"http:\/\/www.ndbc.noaa.gov\/view_text_file.php?filename=44025h2011.txt.gz&amp;dir=data\/historical\/stdmet\/%3C\/a\">http:\/\/www.ndbc.noaa.gov\/view_text_file.php?filename=44025h2011.txt.gz&amp;dir=data\/historical\/stdmet\/&lt;\/a<\/a>&gt;\"<\/code><\/div>\n<div><\/div>\n<div><code>raw_data &lt;- read.csv(file, header=T, skip=<\/code><code>1<\/code><code>)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Files From Other Software<\/strong><\/p>\n<p>Often I will have Excel files, SPSS files, or SAS dataset set to me. \u00a0Once again I can either export the data as a csv file and then import using the\u00a0<em>read.csv<\/em>\u00a0function. \u00a0However, taking that approach every time means that there is an additional step. \u00a0By adding unnecessary steps to a process increases the risk that the data might get corrupted due to human error. \u00a0Furthermore, if the data is updated from time to time then the data that you downloaded last week may not have the most current data.<\/p>\n<p>&nbsp;<\/p>\n<p><em>SPSS<\/em><\/p>\n<div>\n<div id=\"highlighter_904031\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<\/td>\n<td>\n<div>\n<div><code>library(foreign)<\/code><\/div>\n<div><code>file &lt;- <\/code><code>\"C:\\\\my_folder\\\\my_file.sav\"<\/code><\/div>\n<div><code>raw &lt;- as.data.frame(read.spss(file))<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p><em>Microsoft Excel<\/em><\/p>\n<div>\n<div id=\"highlighter_935563\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<\/td>\n<td>\n<div>\n<div><code>library(XLConnect)<\/code><\/div>\n<div><\/div>\n<div><code>file &lt;- <\/code><code>\"C:\\\\my_folder\\\\my_file.xlsx\"<\/code><\/div>\n<div><code>raw_wb &lt;- loadWorkbook(file, create=F)<\/code><\/div>\n<div><code>raw &lt;- as.data.frame( readWorksheet(raw_wb, sheet=<\/code><code>'Sheet1'<\/code><code>) )<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Data From Relational Databases<\/strong><\/p>\n<p>There is the RMySQL library which is very useful. \u00a0However, I have generally been in the habit of using the RODBC library. \u00a0The reason for this is that I will often jump between databases (e.g. Oracle, MSSQL, MySQL). \u00a0By using the RODBC library I can keep all of my connections in one location and use the same functions regardless of the databases. \u00a0This example below will work on any standard SQL database. \u00a0You just need to make sure you set up an ODBC connection call (in this example) MY_DATABASE.<\/p>\n<div>\n<div id=\"highlighter_750113\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<\/td>\n<td>\n<div>\n<div><code>library(RODBC)<\/code><\/div>\n<div><code>channel &lt;- odbcConnect(<\/code><code>\"MY_DATABASE\"<\/code><code>, uid=<\/code><code>\"username\"<\/code><code>, pwd=<\/code><code>\"password\"<\/code><code>)<\/code><\/div>\n<div><\/div>\n<div><code>raw &lt;- sqlQuery(channel, <\/code><code>\"SELECT * FROM Table1\"<\/code><code>);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Data from Non-Relational Databases<\/strong><\/p>\n<p>R has the capability to pull data from non-relational databases. \u00a0These include Hadoop (rhbase), Cassandra (RCassandra), MongoDB (rmongodb). \u00a0I personally have not used RCassandra but here is the\u00a0<a title=\"RCassandra Documentation\" href=\"http:\/\/cran.r-project.org\/web\/packages\/RCassandra\/RCassandra.pdf\" target=\"_blank\" rel=\"noopener\">documentation<\/a>. \u00a0The example here uses MongoDB using an\u00a0<a title=\"MongoDB Schema Design\" href=\"http:\/\/www.mongodb.org\/display\/DOCS\/Schema+Design\" target=\"_blank\" rel=\"noopener\">example<\/a>\u00a0provided by MongoDB.<\/p>\n<div>\n<div id=\"highlighter_864133\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<div>7<\/div>\n<div>8<\/div>\n<div>9<\/div>\n<div>10<\/div>\n<div>11<\/div>\n<div>12<\/div>\n<div>13<\/div>\n<div>14<\/div>\n<div>15<\/div>\n<div>16<\/div>\n<div>17<\/div>\n<div>18<\/div>\n<div>19<\/div>\n<div>20<\/div>\n<div>21<\/div>\n<div>22<\/div>\n<div>23<\/div>\n<div>24<\/div>\n<div>25<\/div>\n<div>26<\/div>\n<div>27<\/div>\n<div>28<\/div>\n<div>29<\/div>\n<div>30<\/div>\n<div>31<\/div>\n<div>32<\/div>\n<div>33<\/div>\n<div>34<\/div>\n<div>35<\/div>\n<div>36<\/div>\n<div>37<\/div>\n<div>38<\/div>\n<div>39<\/div>\n<div>40<\/div>\n<div>41<\/div>\n<div>42<\/div>\n<\/td>\n<td>\n<div>\n<div><code>library(rmongodb)<\/code><\/div>\n<div><code>MyMongodb &lt;- <\/code><code>\"test\"<\/code><\/div>\n<div><code>ns &lt;- <\/code><code>\"articles\"<\/code><\/div>\n<div><code>mongo &lt;- mongo.create(db=MyMmongodb)<\/code><\/div>\n<div><\/div>\n<div><code>list.d &lt;- mongo.bson.from.list(list(<\/code><\/div>\n<div><code>\"_id\"<\/code><code>=<\/code><code>\"wes\"<\/code><code>,<\/code><\/div>\n<div><code>name=list(first=<\/code><code>\"Wesley\"<\/code><code>, last=<\/code><code>\"\"<\/code><code>),<\/code><\/div>\n<div><code>sex=<\/code><code>\"M\"<\/code><code>,<\/code><\/div>\n<div><code>age=<\/code><code>40<\/code><code>,<\/code><\/div>\n<div><code>value=c(<\/code><code>\"7\"<\/code><code>, <\/code><code>\"5\"<\/code><code>,<\/code><code>\"8\"<\/code><code>,<\/code><code>\"2\"<\/code><code>)<\/code><\/div>\n<div><code>))<\/code><\/div>\n<div><code>mongo.insert(mongo, <\/code><code>\"test.MyPeople\"<\/code><code>, list.d)<\/code><\/div>\n<div><code>list.d<\/code><code>2<\/code> <code>&lt;- mongo.bson.from.list(list(<\/code><\/div>\n<div><code>\"_id\"<\/code><code>=<\/code><code>\"Article1\"<\/code><code>,<\/code><\/div>\n<div><code>when=mongo.timestamp.create(strptime(<\/code><code>\"2012-10-01 01:30:00\"<\/code><code>,<\/code><\/div>\n<div><code>\"%Y-%m-%d %H:%M:%s\"<\/code><code>), increment=<\/code><code>1<\/code><code>),<\/code><\/div>\n<div><code>author=<\/code><code>\"wes\"<\/code><code>,<\/code><\/div>\n<div><code>title=<\/code><code>\"Importing Data Into R from Different Sources\"<\/code><code>,<\/code><\/div>\n<div><code>text=<\/code><code>\"Provides R code on how to import data into R from different sources.\"<\/code><code>,<\/code><\/div>\n<div><code>tags=c(<\/code><code>\"R\"<\/code><code>, <\/code><code>\"MongoDB\"<\/code><code>, <\/code><code>\"Cassandra\"<\/code><code>,<\/code><code>\"MySQL\"<\/code><code>,<\/code><code>\"Excel\"<\/code><code>,<\/code><code>\"SPSS\"<\/code><code>),<\/code><\/div>\n<div><code>comments=list(<\/code><\/div>\n<div><code>list(<\/code><\/div>\n<div><code>who=<\/code><code>\"wes\"<\/code><code>,<\/code><\/div>\n<div><code>when=mongo.timestamp.create(strptime(<\/code><code>\"2012-10-01 01:35:00\"<\/code><code>,<\/code><\/div>\n<div><code>\"%Y-%m-%d %H:%M:%s\"<\/code><code>), increment=<\/code><code>1<\/code><code>),<\/code><\/div>\n<div><code>comment=<\/code><code>\"I'm open to comments or suggestions on other data sources to include.\"<\/code><\/div>\n<div><code>)<\/code><\/div>\n<div><code>)<\/code><\/div>\n<div><code>)<\/code><\/div>\n<div><code>)<\/code><\/div>\n<div><code>list.d<\/code><code>2<\/code><\/div>\n<div><code>mongo.insert(mongo, <\/code><code>\"test.MyArticles\"<\/code><code>, list.d<\/code><code>2<\/code><code>)<\/code><\/div>\n<div><\/div>\n<div><code>res &lt;- mongo.find(mongo, <\/code><code>\"test.MyArticles\"<\/code><code>, query=list(author=<\/code><code>\"wes\"<\/code><code>), fields=list(title=<\/code><code>1<\/code><code>L))<\/code><\/div>\n<div><code>out &lt;- NULL<\/code><\/div>\n<div><code>while (mongo.cursor.next(res)){<\/code><\/div>\n<div><code>out &lt;- c(out, list(mongo.bson.to.list(mongo.cursor.value(res))))<\/code><\/div>\n<div><\/div>\n<div><code>}<\/code><\/div>\n<div><\/div>\n<div><code>out<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>Copied and Pasted Text<\/strong><\/p>\n<div>\n<div id=\"highlighter_835727\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<div>7<\/div>\n<div>8<\/div>\n<div>9<\/div>\n<div>10<\/div>\n<div>11<\/div>\n<div>12<\/div>\n<div>13<\/div>\n<div>14<\/div>\n<div>15<\/div>\n<div>16<\/div>\n<div>17<\/div>\n<div>18<\/div>\n<div>19<\/div>\n<div>20<\/div>\n<div>21<\/div>\n<div>22<\/div>\n<div>23<\/div>\n<div>24<\/div>\n<div>25<\/div>\n<div>26<\/div>\n<div>27<\/div>\n<div>28<\/div>\n<div>29<\/div>\n<div>30<\/div>\n<div>31<\/div>\n<div>32<\/div>\n<div>33<\/div>\n<div>34<\/div>\n<div>35<\/div>\n<div>36<\/div>\n<div>37<\/div>\n<div>38<\/div>\n<div>39<\/div>\n<div>40<\/div>\n<div>41<\/div>\n<div>42<\/div>\n<div>43<\/div>\n<div>44<\/div>\n<div>45<\/div>\n<div>46<\/div>\n<div>47<\/div>\n<div>48<\/div>\n<div>49<\/div>\n<div>50<\/div>\n<div>51<\/div>\n<div>52<\/div>\n<div>53<\/div>\n<div>54<\/div>\n<div>55<\/div>\n<div>56<\/div>\n<div>57<\/div>\n<div>58<\/div>\n<div>59<\/div>\n<div>60<\/div>\n<\/td>\n<td>\n<div>\n<div><code>raw_txt &lt;- \"<\/code><\/div>\n<div><code>STATE READY TOTAL<\/code><\/div>\n<div><code>AL <\/code><code>36<\/code> <code>36<\/code><\/div>\n<div><code>AK <\/code><code>5<\/code> <code>8<\/code><\/div>\n<div><code>AZ <\/code><code>15<\/code> <code>16<\/code><\/div>\n<div><code>AR <\/code><code>21<\/code> <code>27<\/code><\/div>\n<div><code>CA <\/code><code>43<\/code> <code>43<\/code><\/div>\n<div><code>CT <\/code><code>56<\/code> <code>68<\/code><\/div>\n<div><code>DE <\/code><code>22<\/code> <code>22<\/code><\/div>\n<div><code>DC <\/code><code>7<\/code> <code>7<\/code><\/div>\n<div><code>FL <\/code><code>130<\/code> <code>132<\/code><\/div>\n<div><code>GA <\/code><code>53<\/code> <code>54<\/code><\/div>\n<div><code>HI <\/code><code>11<\/code> <code>16<\/code><\/div>\n<div><code>ID <\/code><code>11<\/code> <code>11<\/code><\/div>\n<div><code>IL <\/code><code>24<\/code> <code>24<\/code><\/div>\n<div><code>IN <\/code><code>65<\/code> <code>77<\/code><\/div>\n<div><code>IA <\/code><code>125<\/code> <code>130<\/code><\/div>\n<div><code>KS <\/code><code>22<\/code> <code>26<\/code><\/div>\n<div><code>KY <\/code><code>34<\/code> <code>34<\/code><\/div>\n<div><code>LA <\/code><code>27<\/code> <code>34<\/code><\/div>\n<div><code>ME <\/code><code>94<\/code> <code>96<\/code><\/div>\n<div><code>MD <\/code><code>25<\/code> <code>26<\/code><\/div>\n<div><code>MA <\/code><code>82<\/code> <code>92<\/code><\/div>\n<div><code>Mi <\/code><code>119<\/code> <code>126<\/code><\/div>\n<div><code>MN <\/code><code>69<\/code> <code>80<\/code><\/div>\n<div><code>MS <\/code><code>43<\/code> <code>43<\/code><\/div>\n<div><code>MO <\/code><code>74<\/code> <code>82<\/code><\/div>\n<div><code>MT <\/code><code>34<\/code> <code>40<\/code><\/div>\n<div><code>NE <\/code><code>9<\/code> <code>13<\/code><\/div>\n<div><code>NV <\/code><code>64<\/code> <code>64<\/code><\/div>\n<div><code>NM <\/code><code>120<\/code> <code>137<\/code><\/div>\n<div><code>NY <\/code><code>60<\/code> <code>62<\/code><\/div>\n<div><code>NJ <\/code><code>29<\/code> <code>33<\/code><\/div>\n<div><code>NH <\/code><code>44<\/code> <code>45<\/code><\/div>\n<div><code>ND <\/code><code>116<\/code> <code>135<\/code><\/div>\n<div><code>NC <\/code><code>29<\/code> <code>33<\/code><\/div>\n<div><code>OH <\/code><code>114<\/code> <code>130<\/code><\/div>\n<div><code>OK <\/code><code>19<\/code> <code>22<\/code><\/div>\n<div><code>PA <\/code><code>101<\/code> <code>131<\/code><\/div>\n<div><code>RI <\/code><code>32<\/code> <code>32<\/code><\/div>\n<div><code>Sc <\/code><code>35<\/code> <code>45<\/code><\/div>\n<div><code>SD <\/code><code>25<\/code> <code>25<\/code><\/div>\n<div><code>TN <\/code><code>30<\/code> <code>34<\/code><\/div>\n<div><code>TX <\/code><code>14<\/code> <code>25<\/code><\/div>\n<div><code>UT <\/code><code>11<\/code> <code>11<\/code><\/div>\n<div><code>VT <\/code><code>33<\/code> <code>49<\/code><\/div>\n<div><code>VA <\/code><code>108<\/code> <code>124<\/code><\/div>\n<div><code>WV <\/code><code>27<\/code> <code>36<\/code><\/div>\n<div><code>WI <\/code><code>122<\/code> <code>125<\/code><\/div>\n<div><code>WY <\/code><code>12<\/code> <code>14<\/code><\/div>\n<div><code>\"<\/code><\/div>\n<div><code>raw_data &lt;- textConnection(raw_txt)<\/code><\/div>\n<div><code>raw &lt;- read.table(raw_data, header=TRUE, comment.char=<\/code><code>\"#\"<\/code><code>, sep=<\/code><code>\"\"<\/code><code>)<\/code><\/div>\n<div><code>close.connection(raw_data)<\/code><\/div>\n<div><\/div>\n<div><code>raw<\/code><\/div>\n<div><\/div>\n<div><code>###Or the following line can be used<\/code><\/div>\n<div><\/div>\n<div><code>raw &lt;- read.table(header=TRUE, text=raw_txt)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>\u00a0Structured Local or Remote Data<\/strong><\/p>\n<p>One feature that I find quite useful is when there is a Web site with a table that I want to analyze. \u00a0R has the capability to read through the HTML and import the table that you want. \u00a0This example uses the\u00a0<em>XML<\/em>\u00a0library and pulls down the population by country in the world. \u00a0Once the data is brought into R it may need to be cleaned up a bit removing unnecessary columns and other stray characters. \u00a0The examples here use remote data from other Web sites. \u00a0If the data is available as a local file then it can be imported in a similar fashion just using filename rather than the URL.<\/p>\n<div>\n<div id=\"highlighter_627778\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<\/td>\n<td>\n<div>\n<div><code>library(XML)<\/code><\/div>\n<div><\/div>\n<div><code>url<\/code> <code>&lt;- <\/code><code>\"<a href=\"http:\/\/en.wikipedia.org\/wiki\/List_of_countries_by_population\">http:\/\/en.wikipedia.org\/wiki\/List_of_countries_by_population<\/a>\"<\/code><\/div>\n<div><code>population = readHTMLTable(<\/code><code>url<\/code><code>, which=<\/code><code>3<\/code><code>)<\/code><\/div>\n<div><code>population<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Or you can use the feature to simple grab XML content. \u00a0I have found this particularly useful when I need geospatial data and need to get the latitude\/longitude of a location (this example uses Open Street Maps API provided by MapQuest). \u00a0This example obtains the results for the\u00a0coordinates\u00a0of the United States White House.<\/p>\n<div>\n<div id=\"highlighter_267496\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<\/td>\n<td>\n<div>\n<div><code>url<\/code> <code>&lt;- <\/code><code>\"<a href=\"http:\/\/open.mapquestapi.com\/geocoding\/v1\/address?location=1600%20Pennsylvania%20Ave\">http:\/\/open.mapquestapi.com\/geocoding\/v1\/address?location=1600%20Pennsylvania%20Ave<\/a>,%20Washington,%20DC&amp;outFormat=xml\"<\/code><\/div>\n<div><code>mygeo &lt;- xmlToDataFrame(<\/code><code>url<\/code><code>)<\/code><\/div>\n<div><code>mygeo$result<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>An alternate approach is to use a JSON format. \u00a0I generally find that JSON is a better format and it can be readily used in most programming languages.<\/p>\n<div>\n<div id=\"highlighter_358656\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<\/td>\n<td>\n<div>\n<div><code>library(rjson)<\/code><\/div>\n<div><code>url<\/code> <code>&lt;- <\/code><code>\"<a href=\"http:\/\/open.mapquestapi.com\/geocoding\/v1\/address?location=1600%20Pennsylvania%20Ave\">http:\/\/open.mapquestapi.com\/geocoding\/v1\/address?location=1600%20Pennsylvania%20Ave<\/a>,%20Washington,%20DC&amp;outFormat=json\"<\/code><\/div>\n<div><\/div>\n<div><code>raw_json &lt;- scan(<\/code><code>url<\/code><code>, <\/code><code>\"\"<\/code><code>, sep=<\/code><code>\"\\n\"<\/code><code>)<\/code><\/div>\n<div><\/div>\n<div><code>mygeo &lt;- fromJSON(raw_json)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I have found that I get data from many different sources. \u00a0These sources range from simple .csv files to more complex relational databases, to structure&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-343","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=343"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/343\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}