<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/importing-data-into-r-part-ii/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://thepracticalr.wordpress.com/2017/01/31/importing-data-into-r-part-ii/"> The Practical R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I recently downloaded the latest version of R Studio and noticed that their import dataset functionality had changed significantly. I had previously written about this <a target="_blank" rel="nofollow" href="https://thepracticalr.wordpress.com/2016/09/23/importing-data-into-r/"><strong>HERE</strong></a> and wanted to provide an update for the current version of RStudio.</p>
<p>When you go to import data using R Studio, you get a menu like this.</p>
<p><img sizes="(max-width: 227px) 100vw, 227px" data-image-description="" data-orig-file="https://i1.wp.com/thepracticalr.files.wordpress.com/2017/01/rstudio-old-import.png?w=456&amp;ssl=1" data-orig-size="227,198" data-image-title="rstudio-old-import" class="wp-image-739" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="739" data-permalink="https://thepracticalr.wordpress.com/2017/01/31/importing-data-into-r-part-ii/rstudio-old-import/#main" alt="rstudio-old-import" data-medium-file="https://i1.wp.com/thepracticalr.files.wordpress.com/2017/01/rstudio-old-import.png?w=456&amp;ssl=1?w=227" data-large-file="https://i1.wp.com/thepracticalr.files.wordpress.com/2017/01/rstudio-old-import.png?w=456&amp;ssl=1?w=227" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i1.wp.com/thepracticalr.files.wordpress.com/2017/01/rstudio-old-import.png?w=456&ssl=1"></p>
<p>If you’re using the latest version of RStudio, when you click “From CSV” you’ll get a popup about downloading a new library ‘readr’.</p>
<p><img sizes="(max-width: 450px) 100vw, 450px" data-image-description="" data-orig-file="https://i1.wp.com/thepracticalr.files.wordpress.com/2017/01/readr1.png?w=456&amp;ssl=1" data-orig-size="450,139" data-image-title="readr" data-comments-opened="1" class="wp-image-747" data-recalc-dims="1" data-attachment-id="747" data-permalink="https://thepracticalr.wordpress.com/2017/01/31/importing-data-into-r-part-ii/readr/#main" alt="readr" data-medium-file="https://i1.wp.com/thepracticalr.files.wordpress.com/2017/01/readr1.png?w=456&amp;ssl=1?w=300" data-large-file="https://i1.wp.com/thepracticalr.files.wordpress.com/2017/01/readr1.png?w=456&amp;ssl=1?w=450" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i1.wp.com/thepracticalr.files.wordpress.com/2017/01/readr1.png?w=456&ssl=1"></p>
<p>Once that has completed, you’ll see the new import data window (shown below).</p>
<p><img sizes="(max-width: 800px) 100vw, 800px" data-image-description="" data-orig-file="https://i0.wp.com/thepracticalr.files.wordpress.com/2017/01/new-import-screen.png?w=456&amp;ssl=1" data-orig-size="1188,569" data-image-title="new-import-screen" data-comments-opened="1" class="wp-image-737" data-recalc-dims="1" data-attachment-id="737" data-permalink="https://thepracticalr.wordpress.com/2017/01/31/importing-data-into-r-part-ii/new-import-screen/#main" alt="new-import-screen" data-medium-file="https://i0.wp.com/thepracticalr.files.wordpress.com/2017/01/new-import-screen.png?w=456&amp;ssl=1?w=300" data-large-file="https://i0.wp.com/thepracticalr.files.wordpress.com/2017/01/new-import-screen.png?w=456&amp;ssl=1?w=800" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/thepracticalr.files.wordpress.com/2017/01/new-import-screen.png?w=456&ssl=1"></p>
<p>Okay, so first let’s make a simple comma delimited data file so we can test out the new import dataset process. I have made a simple file called “x-y-data.txt” as shown below. If you make this same file (no spaces, just a comma to separate the x column from the y column) then we can do this exercise together.</p>
<p><img sizes="(max-width: 201px) 100vw, 201px" data-image-description="" data-orig-file="https://i0.wp.com/thepracticalr.files.wordpress.com/2017/01/x-y-data.png?w=456&amp;ssl=1" data-orig-size="201,174" data-image-title="x-y-data" data-comments-opened="1" class="wp-image-755" data-recalc-dims="1" data-attachment-id="755" data-permalink="https://thepracticalr.wordpress.com/2017/01/31/importing-data-into-r-part-ii/x-y-data/#main" alt="x-y-data" data-medium-file="https://i0.wp.com/thepracticalr.files.wordpress.com/2017/01/x-y-data.png?w=456&amp;ssl=1?w=201" data-large-file="https://i0.wp.com/thepracticalr.files.wordpress.com/2017/01/x-y-data.png?w=456&amp;ssl=1?w=201" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/thepracticalr.files.wordpress.com/2017/01/x-y-data.png?w=456&ssl=1"></p>
<p>Now, let’s use the RStudio import to bring in the file “x-y-data.txt”. Here’s a screen grab of the import screen with my x-y dataset.</p>
<p><img sizes="(max-width: 800px) 100vw, 800px" data-image-description="" data-orig-file="https://i2.wp.com/thepracticalr.files.wordpress.com/2017/01/import-data.png?w=456&amp;ssl=1" data-orig-size="1187,564" data-image-title="import-data" data-comments-opened="1" class="wp-image-760" data-recalc-dims="1" data-attachment-id="760" data-permalink="https://thepracticalr.wordpress.com/2017/01/31/importing-data-into-r-part-ii/import-data/#main" alt="import-data" data-medium-file="https://i2.wp.com/thepracticalr.files.wordpress.com/2017/01/import-data.png?w=456&amp;ssl=1?w=300" data-large-file="https://i2.wp.com/thepracticalr.files.wordpress.com/2017/01/import-data.png?w=456&amp;ssl=1?w=800" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i2.wp.com/thepracticalr.files.wordpress.com/2017/01/import-data.png?w=456&ssl=1"></p>
<p>We can see that RStudio has used the first row as names, has recognized that it is a comma delimited file, and has read both x and y values as integers. Everything looks good, so I click “import”.</p>
<p>It was after this import process, that I had tried running some of my standard functions, such as making an empirical CDF (cumulative density function) and then I ran into problems. So let’s check the type of data we have imported.</p>
<pre><code># get the data structure
typeof(x_y_data)
#[1] &quot;list&quot;
class(x_y_data)
#[1] &quot;tbl_df&quot;     &quot;tbl&quot;        &quot;data.frame&quot;
</code></pre>
<p>While the old RStudio would have imported this as a <strong>matrix</strong> by default, this latest version of RStudio imports data as a data frame by default. Apparently RStudio has created their own version of a data frame called a “tbl_df” or tibble data frame. When you use the ‘readr’ package, your data is imported automatically as a “tbl_df”.</p>
<p>Now this isn’t necessarily a bad thing, in fact it seems like there is some nice functionality gained by using the “tbl_df” format. This change just broke some of my previously written code and it’s good to know what RStudio is doing by default.</p>
<p>If we wanted to get back to the matrix format, we can do this will a simple <strong>as.matrix</strong> function. From there we can verify it was converted using the <strong>typeof</strong> and <strong>class</strong> functions.</p>
<pre><code># convert to a matrix
data&lt;-as.matrix(x_y_data)
#     x  y
#[1,] 1  2
#[2,] 2  4
#[3,] 3  6
#[4,] 4  8
#[5,] 5 10

typeof(data)
#[1] &quot;integer&quot;
class(data)
#[1] &quot;matrix&quot;
</code></pre>
<p>You can read more about the new Tibble structure at these websites:</p>
<p><a target="_blank" rel="nofollow" href="https://blog.rstudio.org/2016/03/24/tibble-1-0-0/">https://blog.rstudio.org/2016/03/24/tibble-1-0-0/</a></p>
<p><a target="_blank" rel="nofollow" href="http://www.sthda.com/english/wiki/tibble-data-format-in-r-best-and-modern-way-to-work-with-your-data">http://www.sthda.com/english/wiki/tibble-data-format-in-r-best-and-modern-way-to-work-with-your-data</a></p>
<p>Enjoy!</p>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thepracticalr.wordpress.com/735/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/thepracticalr.wordpress.com/735/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></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://thepracticalr.wordpress.com/2017/01/31/importing-data-into-r-part-ii/"> The Practical R</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/fsUVbeu74Vc"></a></div>