]> code.communitydata.science - stats_class_2020.git/commitdiff
adding data import stuff
authoraaronshaw <aaron.d.shaw@gmail.com>
Wed, 30 Sep 2020 04:30:59 +0000 (23:30 -0500)
committeraaronshaw <aaron.d.shaw@gmail.com>
Wed, 30 Sep 2020 04:30:59 +0000 (23:30 -0500)
r_tutorials/w03a-R_tutorial.html
r_tutorials/w03a-R_tutorial.pdf
r_tutorials/w03a-R_tutorial.rmd

index 1608264cd3c02ff7a340a05974793a9bc702464d..9ee7dd2fbf7cde57873cffbd59008977c4a4fb82 100644 (file)
@@ -1621,6 +1621,18 @@ my.mean &lt;- function(z) {
     return(out.value)
 }</code></pre>
 </div>
+<div id="specifying-variable-classes-with-data-import" class="section level1">
+<h1><span class="header-section-number">4</span> Specifying variable classes with data import</h1>
+<p>Aaron C. asked a question about whether/how you might specify variable classes when you’re importing data. Aaron S. punted at the time, so here’s a slightly more specific reply.</p>
+<p>The short answer is, “yes, R can do this.” The details depend on exactly which function you use to import the data in question (and that depends partly on the file format…etc.).</p>
+<p>The most helpful place to look for more information is the help documentation for whatever import function you might be working with. For example, the <code>read.csv()</code> function that gets introduced in the next R tutorial takes an optional argument for colClasses that allows you to specify a vector of classes (e.g., <code>c(&quot;character&quot;, &quot;factor&quot;, &quot;integer&quot;, &quot;character&quot;)</code>) corresponding to the classes you want R to assume for each incoming column of the data.</p>
+<p>Try reading <code>help(read.csv)</code> and look at the documentation for the <code>colClasses</code> argument to learn more.</p>
+<div id="r-guesses-the-classes-of-variables-when-you-import-them" class="section level2">
+<h2><span class="header-section-number">4.1</span> R guesses the classes of variables when you import them</h2>
+<p>Aaron and Nick both made comments about R guessing the classes of variables when you import data. The nature and quality of these guesses can depend on the import function there too.</p>
+<p>Most Base R import stuff makes guesses you might think of as somewhat brittle (assumptions (e.g., looking at just the first five values to inform the guess. In contrast, the Tidyverse data import commands usually use a larger and more random sample of values from each column to make guesses (which are therefore much better).</p>
+</div>
+</div>
 
 
 
index fd72d815af0328d8c94b5c3f424a978dadf18491..8fb68a75160a670097e7e8e3e2c6243e71403c7f 100644 (file)
Binary files a/r_tutorials/w03a-R_tutorial.pdf and b/r_tutorials/w03a-R_tutorial.pdf differ
index 49e44065b183aafeec93a1afdc0045fa906df945..385bfb8b3c8d41373cf82bffea1c275882481f70 100644 (file)
@@ -120,4 +120,19 @@ You can also use an option in RMarkdown's code chunks to call `tidy=TRUE` *insid
 ```{r, tidy=TRUE}
 ## messy chunk with `tidy=TRUE` chunk option:
 my.mean <- function(z){z<-z[!is.na(z)];sigma<-sum(z);n<-length(z);out.value<-sigma/n;return(out.value)}
-```
\ No newline at end of file
+```
+
+# Specifying variable classes with data import
+
+Aaron C. asked a question about whether/how you might specify variable classes when you're importing data. Aaron S. punted at the time, so here's a slightly more specific reply.
+
+The short answer is, "yes, R can do this." The details depend on exactly which function you use to import the data in question (and that depends partly on the file format...etc.).
+
+The most helpful place to look for more information is the help documentation for whatever import function you might be working with. For example, the `read.csv()` function that gets introduced in the next R tutorial takes an optional argument for colClasses that allows you to specify a vector of classes (e.g., `c("character", "factor", "integer", "character")`) corresponding to the classes you want R to assume for each incoming column of the data.
+
+Try reading `help(read.csv)` and look at the documentation for the `colClasses` argument to learn more.
+
+## R guesses the classes of variables when you import them
+Aaron and Nick both made comments about R guessing the classes of variables when you import data. The nature and quality of these guesses can depend on the import function there too.
+
+Most Base R import stuff makes guesses you might think of as somewhat brittle (assumptions (e.g., looking at just the first five values to inform the guess. In contrast, the Tidyverse data import commands usually use a larger and more random sample of values from each column to make guesses (which are therefore much better).

Community Data Science Collective || Want to submit a patch?