<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/how-to-access-datasets-in-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.datazar.com/how-to-access-datasets-in-r-6896f34893ee?source=rss----e2c7e6e1c75--r_language"> R Language in Datazar Blog on Medium</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Have you spent hours, pulling your hair out trying to figure out how to access datasets in R? Once imported to a variable, columns from a dataset (eg: CSV) can be very tricky to access. Sometimes columns contain spaces, funky characters or other incosistencies. Here are some examples on how to access the data from CSV and JSON datasets.</p>
<h3>CSV</h3>
<figure><img alt="" src="https://i0.wp.com/cdn-images-1.medium.com/max/1024/1*9ek1uGEV7EtGEn_eQfORfA.png?w=456&ssl=1" data-recalc-dims="1"><figcaption>We’ll use this CSV dataset since it has *very* long column names.</figcaption></figure>
<ol>
<li>Read File: csvDataset&lt;-read.csv(&quot;Global Carbon Emissions Record 1751-2013&quot;)</li>
</ol>
<p>2. Access Columns: csvDataset$Total.carbon.emissions.from.fossil.fuel.consumption.and.cement.production..million.metric.tons.of.C.</p>
<p>As you can see here, the blank spaces AND parantheses got replaced by a period . .This is actually pretty useful because you can just use the period for other special characters, helping you get to variables faster.</p>
<p>You can always head(csvDataset) to look at the column names (and first few rows) to get the actual column names used to call them.</p>
<h3>JSON</h3>
<figure><img alt="" src="https://i1.wp.com/cdn-images-1.medium.com/max/834/1*WukAwuCVgeT_bSmCF7BiTg.png?w=456&ssl=1" data-recalc-dims="1"><figcaption>We’ll use this simple JSON dataset from NASA showing meteorite impacts.</figcaption></figure>
<p>For JSON, we’re going to load an external library.</p>
<ol>
<li>Load rjson library: library(rjson)</li>
<li>Read File: jsonDataset&lt;-fromJSON(file=&quot;city_country_meteor.json&quot;)</li>
<li>Access an Object: jsonDataset[1] (gives you the first object)</li>
</ol>
<figure><img alt="" src="https://i1.wp.com/cdn-images-1.medium.com/max/1024/1*YG9I6tkOsF4-LEW5lWwlOA.png?w=456&ssl=1" data-recalc-dims="1"></figure>
<p>Link to datasets and example R notebook: <a rel="nofollow" href="https://www.datazar.com/project/p556632b8-4760-4d16-b787-2dbe74b3b1a4/files" target="_blank">https://www.datazar.com/project/p556632b8-4760-4d16-b787-2dbe74b3b1a4/files</a></p>
<p><img width="1" src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6896f34893ee" height="1"></p>
<hr>
<p><a rel="nofollow" href="https://blog.datazar.com/how-to-access-datasets-in-r-6896f34893ee" target="_blank">How to Access Datasets in R</a> was originally published in <a rel="nofollow" href="https://blog.datazar.com/" target="_blank">Datazar Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://blog.datazar.com/how-to-access-datasets-in-r-6896f34893ee?source=rss----e2c7e6e1c75--r_language"> R Language in Datazar Blog on Medium</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/o8XGLbmJknY" height="1"></a></div>