{"appState":{"pageLoadApiCallsStatus":true},"categoryState":{"relatedCategories":{"headers":{"timestamp":"2025-04-17T16:01:07+00:00"},"categoryId":33607,"data":{"title":"R","slug":"r","image":{"src":null,"width":0,"height":0},"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"R","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"},"slug":"r","categoryId":33607}],"parentCategory":{"categoryId":33592,"title":"Programming & Web Design","slug":"programming-web-design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"}},"childCategories":[],"description":"R is a favorite of data scientists and statisticians everywhere, with its ability to crunch large datasets and deal with scientific information. ","relatedArticles":{"self":"https://dummies-api.dummies.com/v2/articles?category=33607&offset=0&size=5"},"hasArticle":true,"hasBook":true,"articleCount":99,"bookCount":5},"_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"}},"relatedCategoriesLoadedStatus":"success"},"listState":{"list":{"count":10,"total":99,"items":[{"headers":{"creationTime":"2023-01-10T19:24:24+00:00","modifiedTime":"2023-01-11T14:37:48+00:00","timestamp":"2023-01-11T15:01:03+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"R","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"},"slug":"r","categoryId":33607}],"title":"R All-in-One For Dummies Cheat Sheet","strippedTitle":"r all-in-one for dummies cheat sheet","slug":"r-all-in-one-for-dummies","canonicalUrl":"","seo":{"metaDescription":"R provides a wide array of functions to help you with your work — from simple statistics to complex analyses.This Cheat Sheet is a handy reference for Base R st","noIndex":0,"noFollow":0},"content":"R provides a wide array of functions to help you with your work — from simple statistics to complex analyses.\r\n\r\nThis Cheat Sheet is a handy reference for Base R statistical functions, interactive applications, machine learning, databases, and images.","description":"R provides a wide array of functions to help you with your work — from simple statistics to complex analyses.\r\n\r\nThis Cheat Sheet is a handy reference for Base R statistical functions, interactive applications, machine learning, databases, and images.","blurb":"","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"primaryCategoryTaxonomy":{"categoryId":33607,"title":"R","slug":"r","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[],"fromCategory":[{"articleId":262959,"title":"Statistical Analysis with R For Dummies Cheat Sheet","slug":"statistical-analysis-with-r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262959"}},{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":296576,"slug":"r-all-in-one-for-dummies","isbn":"9781119983699","categoryList":["technology","programming-web-design","r"],"amazon":{"default":"https://www.amazon.com/gp/product/111998369X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/111998369X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/111998369X-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/111998369X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/111998369X/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/r-all-in-one-for-dummies-cover-9781119983699-203x255.jpg","width":203,"height":255},"title":"R All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b><b data-author-id=\"9759\">Joseph Schmuller</b></b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p>","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119983699&quot;]}]\" id=\"du-slot-63becf2f29be4\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119983699&quot;]}]\" id=\"du-slot-63becf2f2a839\"></div></div>"},"articleType":{"articleType":"Cheat Sheet","articleList":[{"articleId":0,"title":"","slug":null,"categoryList":[],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/"}}],"content":[{"title":"Base R statistical functions","thumb":null,"image":null,"content":"<p>Here&#8217;s a selection of statistical functions that come with the standard R installation. You’ll find many others in R packages.</p>\n<p><strong>Central Tendency and Variability</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"139\"><strong>Function</strong></td>\n<td width=\"436\"><strong>What it calculates</strong></td>\n</tr>\n<tr>\n<td width=\"139\">mean(x)</td>\n<td width=\"436\">Mean of the numbers in vector x</td>\n</tr>\n<tr>\n<td width=\"139\">median(x)</td>\n<td width=\"436\">Median of the numbers in vector x</td>\n</tr>\n<tr>\n<td width=\"139\">var(x)</td>\n<td width=\"436\">Estimated variance of the population from which the numbers in vector x are sampled</td>\n</tr>\n<tr>\n<td width=\"139\">sd(x)</td>\n<td width=\"436\">Estimated standard deviation of the population from which the numbers in vector x are sampled</td>\n</tr>\n<tr>\n<td width=\"139\">scale(x)</td>\n<td width=\"436\">Standard scores (<em>z-</em>scores) for the numbers in vector x</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n<p><strong>Relative Standing</strong></p>\n<table width=\"576\">\n<tbody>\n<tr>\n<td colspan=\"2\" width=\"576\"></td>\n</tr>\n<tr>\n<td width=\"277\"><strong>Function</strong></td>\n<td width=\"298\"><strong>What it calculates</strong></td>\n</tr>\n<tr>\n<td width=\"277\">sort(x)</td>\n<td width=\"298\">The numbers in vector x in increasing order</td>\n</tr>\n<tr>\n<td width=\"277\">sort(x)[n]</td>\n<td width=\"298\">The <em>n</em>th smallest number in vector x</td>\n</tr>\n<tr>\n<td width=\"277\">rank(x)</td>\n<td width=\"298\">Ranks of the numbers (in increasing order) in vector x</td>\n</tr>\n<tr>\n<td width=\"277\">rank(-x)</td>\n<td width=\"298\">Ranks of the numbers (in decreasing order) in vector x</td>\n</tr>\n<tr>\n<td width=\"277\">rank(x, ties.method= “average”)</td>\n<td width=\"298\">Ranks of the numbers (in increasing order) in vector x, with tied numbers given the average of the ranks that the ties would have attained</td>\n</tr>\n<tr>\n<td width=\"277\">rank(x, ties.method=  “min”)</td>\n<td width=\"298\">Ranks of the numbers (in increasing order) in vector x, with tied numbers given the minimum of the ranks that the ties would have attained</td>\n</tr>\n<tr>\n<td width=\"277\">rank(x, ties.method = “max”)</td>\n<td width=\"298\">Ranks of the numbers (in increasing order) in vector x, with tied numbers given the maximum of the ranks that the ties would have attained</td>\n</tr>\n<tr>\n<td width=\"277\">quantile(x)</td>\n<td width=\"298\">The 0th, 25th, 50th, 75th, and 100th percentiles (the <em>quartiles, </em>in other words) of the numbers in vector x. (That’s not a misprint: quantile(x) returns the quartiles of x.)</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n<p><strong><em>t-</em>tests</strong></p>\n<table width=\"576\">\n<tbody>\n<tr>\n<td></td>\n<td width=\"386\"></td>\n</tr>\n<tr>\n<td width=\"190\"><strong>Function</strong></td>\n<td width=\"386\"><strong>What it calculates</strong></td>\n</tr>\n<tr>\n<td width=\"190\">t.test(x,mu=n, alternative = “two.sided”)</td>\n<td width=\"386\">Two-tailed <em>t-</em>test that the mean of the numbers in vector <em>x </em>is different from <em>n</em>.</td>\n</tr>\n<tr>\n<td width=\"190\">t.test(x,mu=n, alternative = “greater”)</td>\n<td width=\"386\">One-tailed <em>t-</em>test that the mean of the numbers in vector <em>x</em> is greater than <em>n</em>.</td>\n</tr>\n<tr>\n<td width=\"190\">t.test(x,mu=n, alternative = “less”)</td>\n<td width=\"386\">One-tailed <em>t-</em>test that the mean of the numbers in vector <em>x</em> is less than <em>n</em>.</td>\n</tr>\n<tr>\n<td width=\"190\">t.test(x,y,mu=0, var.equal  = TRUE, alternative = “two.sided”)</td>\n<td width=\"386\">Two-tailed <em>t-</em>test that the mean of the numbers in vector <em>x</em> is different from the mean of the numbers in vector <em>y</em>. The variances in the two vectors are assumed to be equal.</td>\n</tr>\n<tr>\n<td width=\"190\">t.test(x,y,mu=0, alternative = “two.sided”, paired  = TRUE)</td>\n<td width=\"386\">Two-tailed <em>t-</em>test that the mean of the numbers in vector <em>x</em> is different from the mean of the numbers in vector <em>y</em>. The vectors represent matched samples.</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n<p><strong>Analysis of Variance (ANOVA)</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"104\"><strong>Function</strong></td>\n<td width=\"468\"><strong>What it calculates</strong></td>\n</tr>\n<tr>\n<td width=\"104\">aov(y~x, data = d)</td>\n<td width=\"468\">Single-factor ANOVA, with the numbers in vector <em>y</em> as the dependent variable and the elements of vector <em>x </em>as the levels of the independent variable. The data are in data frame <em>d</em>.</td>\n</tr>\n<tr>\n<td width=\"104\">aov(y~x + Error(w/x), data = d)</td>\n<td width=\"468\">Repeated Measures ANOVA, with the numbers in vector <em>y </em>as the dependent variable and the elements in vector <em>x </em>as the levels of an independent variable. Error(w/x) indicates that each element in vector <em>w</em> experiences all the levels of <em>x</em>. (In other words, <em>x</em> is a repeated measure.) The data are in data frame <em>d</em>.</td>\n</tr>\n<tr>\n<td width=\"104\">aov(y~x*z, data = d)</td>\n<td width=\"468\">Two-factor ANOVA, with the numbers in vector<em> y</em> as the dependent variable and the elements of vectors <em>x </em>and <em>z</em> as the levels of the two independent variables. The data are in data frame <em>d</em>.</td>\n</tr>\n<tr>\n<td width=\"104\">aov(y~x*z + Error(w/z), data = d)</td>\n<td width=\"468\">Mixed ANOVA, with the numbers in vector <em>z</em> as the dependent variable and the elements of vectors <em>x</em> and <em>y</em> as the levels of the two independent variables. Error(w/z) indicates that each element in vector <em>w</em> experiences all the levels of <em>z</em>. (In other words, <em>z</em> is a repeated measure.) The data are in data frame <em>d</em>.</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n<p><strong>Correlation and regression</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"106\"><strong>Function</strong></td>\n<td width=\"466\"><strong>What it calculates</strong></td>\n</tr>\n<tr>\n<td width=\"106\">cor(x,y)</td>\n<td width=\"466\">Correlation coefficient between the numbers in vector <em>x</em> and the numbers in vector <em>y</em></td>\n</tr>\n<tr>\n<td width=\"106\">cor.test(x,y)</td>\n<td width=\"466\">Correlation coefficient between the numbers in vector <em>x </em>and the numbers in vector <em>y</em>, along with a <em>t-</em>test of the significance of the correlation coefficient.</td>\n</tr>\n<tr>\n<td width=\"106\">lm(y~x, data = d)</td>\n<td width=\"466\">Linear regression analysis with the numbers in vector <em>y</em> as the dependent variable and the numbers in vector <em>x </em>as the independent variable. Data are in data frame <em>d</em>.</td>\n</tr>\n<tr>\n<td width=\"106\">coefficients(a)</td>\n<td width=\"466\">Slope and intercept of linear regression model <em>a.</em></td>\n</tr>\n<tr>\n<td width=\"106\">confint(a)</td>\n<td width=\"466\">Confidence intervals of the slope and intercept of linear regression model <em>a</em>.</td>\n</tr>\n<tr>\n<td width=\"106\">lm(y~x+z, data = d)</td>\n<td width=\"466\">Multiple regression analysis with the numbers in vector <em>y </em>as the dependent variable and the numbers in vectors<em> x</em> and<em> z</em> as the independent variables. Data are in data frame <em>d</em>.</td>\n</tr>\n</tbody>\n</table>\n<p class=\"article-tips tip\">When you carry out an ANOVA or a regression analysis, store the analysis in a list — for example: a &lt;- lm(y~x, data = d). Then, to see the tabled results, use the summary() function: summary(a)</p>\n"},{"title":"Interacting with a user","thumb":null,"image":null,"content":"<p>R provides the shiny package and the shinydashboard package for developing interactive applications. Here are selected functions from these packages.</p>\n<p>&nbsp;</p>\n<p><strong>Functions from the shiny package</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"112\"><strong>Function</strong></td>\n<td width=\"463\"><strong>What it does</strong></td>\n</tr>\n<tr>\n<td width=\"112\">shinyApp()</td>\n<td width=\"463\">Ties a user interface and a server into a shiny application</td>\n</tr>\n<tr>\n<td width=\"112\">fluidPage()</td>\n<td width=\"463\">Creates a browser page that changes with the width of the browser</td>\n</tr>\n<tr>\n<td width=\"112\">sliderInput()</td>\n<td width=\"463\">Defines a slider and its input for a shiny user interface</td>\n</tr>\n<tr>\n<td width=\"112\">plotOutput()</td>\n<td width=\"463\">Reserves a shiny user interface area for a plot</td>\n</tr>\n<tr>\n<td width=\"112\">renderPlot()</td>\n<td width=\"463\">Draws the plot on a shiny user interface</td>\n</tr>\n<tr>\n<td width=\"112\">textOutput()</td>\n<td width=\"463\">Reserves a shiny user interface area for text</td>\n</tr>\n<tr>\n<td width=\"112\">renderText()</td>\n<td width=\"463\">Adds text to a shiny user interface</td>\n</tr>\n<tr>\n<td width=\"112\">selectInput()</td>\n<td width=\"463\">Creates a drop-down menu on a shiny user interface</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n<p><strong>Functions from the shinydashboard package</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"147\"><strong>Function</strong></td>\n<td width=\"426\"><strong>What it creates for a shinydashboard page</strong></td>\n</tr>\n<tr>\n<td width=\"147\">dashboardPage()</td>\n<td width=\"426\">The page</td>\n</tr>\n<tr>\n<td width=\"147\">dashboardHeader()</td>\n<td width=\"426\">Page header</td>\n</tr>\n<tr>\n<td width=\"147\">dashboardSidebar()</td>\n<td width=\"426\">Page sidebar</td>\n</tr>\n<tr>\n<td width=\"147\">sidebarMenu()</td>\n<td width=\"426\">A menu for a sidebar</td>\n</tr>\n<tr>\n<td width=\"147\">menuItem()</td>\n<td width=\"426\">An item for a menu</td>\n</tr>\n<tr>\n<td width=\"147\">dashboardBody()</td>\n<td width=\"426\">Page body</td>\n</tr>\n<tr>\n<td width=\"147\">fluidRow()</td>\n<td width=\"426\">A variable-width row inside the dashboard body</td>\n</tr>\n<tr>\n<td width=\"147\">box()</td>\n<td width=\"426\">A box inside a row</td>\n</tr>\n<tr>\n<td width=\"147\">valueBoxOutput()</td>\n<td width=\"426\">A reserved space for a value box</td>\n</tr>\n<tr>\n<td width=\"147\">renderValueBox</td>\n<td width=\"426\">Reactive context for a value box</td>\n</tr>\n<tr>\n<td width=\"147\">valueBox</td>\n<td width=\"426\">A value box</td>\n</tr>\n<tr>\n<td width=\"147\">column()</td>\n<td width=\"426\">A column within a fluid row</td>\n</tr>\n<tr>\n<td width=\"147\">tabBox()</td>\n<td width=\"426\">A tab for a tabbed page</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"Machine learning","thumb":null,"image":null,"content":"<p>R provides a number of packages and functions for machine learning. Here are some of them.</p>\n<p><strong>Machine learning packages and functions</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"88\"><strong>Package</strong></td>\n<td width=\"140\"><strong>Function</strong></td>\n<td width=\"347\"><strong>What it does</strong></td>\n</tr>\n<tr>\n<td width=\"88\">rattle</td>\n<td width=\"140\">rattle()</td>\n<td width=\"347\">Opens the Rattle graphical user interface</td>\n</tr>\n<tr>\n<td width=\"88\">rpart</td>\n<td width=\"140\">rpart()</td>\n<td width=\"347\">Creates a decision tree</td>\n</tr>\n<tr>\n<td width=\"88\">rpart.plot</td>\n<td width=\"140\">prp()</td>\n<td width=\"347\">Draws a decision tree</td>\n</tr>\n<tr>\n<td width=\"88\">randomForest</td>\n<td width=\"140\">randomForest()</td>\n<td width=\"347\">Creates a random forest of decision trees</td>\n</tr>\n<tr>\n<td width=\"88\">rattle</td>\n<td width=\"140\">printRandomForests()</td>\n<td width=\"347\">Prints the rules of a forest’s individual decision trees</td>\n</tr>\n<tr>\n<td width=\"88\">e1071</td>\n<td width=\"140\">svm()</td>\n<td width=\"347\">Trains a support vector machine</td>\n</tr>\n<tr>\n<td width=\"88\">e1071</td>\n<td width=\"140\">predict()</td>\n<td width=\"347\">Creates a vector of predicted classifications based on a support vector machine</td>\n</tr>\n<tr>\n<td width=\"88\">kernlab</td>\n<td width=\"140\">ksvm()</td>\n<td width=\"347\">Trains a support vector machine</td>\n</tr>\n<tr>\n<td width=\"88\">base R</td>\n<td width=\"140\">kmeans()</td>\n<td width=\"347\">Creates a k-means clustering analysis</td>\n</tr>\n<tr>\n<td width=\"88\">nnet</td>\n<td width=\"140\">nnet()</td>\n<td width=\"347\">Creates a neural network with one hidden layer</td>\n</tr>\n<tr>\n<td width=\"88\">NeuralNetTools</td>\n<td width=\"140\">plotnet()</td>\n<td width=\"347\">Draws a neural network</td>\n</tr>\n<tr>\n<td width=\"88\">nnet</td>\n<td width=\"140\">predict()</td>\n<td width=\"347\">Creates a vector of predictions based on a neural network</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"Databases","thumb":null,"image":null,"content":"<p>Created for statistical analysis, R has wide array of packages and functions for dealing with large amounts of data. This selection is the tip of the iceberg’s tip.</p>\n<p><strong>Packages and functions for exploring databases</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"88\"><strong>Package</strong></td>\n<td width=\"140\"><strong>Function</strong></td>\n<td width=\"347\"><strong>What it does</strong></td>\n</tr>\n<tr>\n<td width=\"88\">didrooRFM</td>\n<td width=\"140\">findRFM()</td>\n<td width=\"347\">Performs a recency, frequency, money analysis on a database of retail transactions</td>\n</tr>\n<tr>\n<td width=\"88\">vcd</td>\n<td width=\"140\">assocstats()</td>\n<td width=\"347\">Calculates statistics for tables of categorical data</td>\n</tr>\n<tr>\n<td width=\"88\">vcd</td>\n<td width=\"140\">assoc()</td>\n<td width=\"347\">Creates a graphic that shows deviations from independence in a table of categorical data</td>\n</tr>\n<tr>\n<td width=\"88\">tidyverse</td>\n<td width=\"140\">glimpse()</td>\n<td width=\"347\">Provides a partial view of a data frame with the columns appearing onscreen as rows</td>\n</tr>\n<tr>\n<td width=\"88\">plotrix</td>\n<td width=\"140\">std.error()</td>\n<td width=\"347\">Calculates the standard error of the mean</td>\n</tr>\n<tr>\n<td width=\"88\">plyr</td>\n<td width=\"140\">inner_join()</td>\n<td width=\"347\">Joins data frames</td>\n</tr>\n<tr>\n<td width=\"88\">lubridate</td>\n<td width=\"140\">wday()</td>\n<td width=\"347\">Returns day of the week of a calendar date</td>\n</tr>\n<tr>\n<td width=\"88\">lubridate</td>\n<td width=\"140\">ymd()</td>\n<td width=\"347\">Returns a date in R date-format</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"Images","thumb":null,"image":null,"content":"<p>Here are some functions to help you get started using R to process images. They all live in the magick package.</p>\n<p><strong>Functions from the magick package</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"137\"><strong>Function</strong></td>\n<td width=\"439\"><strong>What it does</strong></td>\n</tr>\n<tr>\n<td width=\"137\">image_read()</td>\n<td width=\"439\">Reads an image into R and turns it into a magick object</td>\n</tr>\n<tr>\n<td width=\"137\">image_resize()</td>\n<td width=\"439\">Resizes an image</td>\n</tr>\n<tr>\n<td width=\"137\">image_rotate()</td>\n<td width=\"439\">Rotates an image</td>\n</tr>\n<tr>\n<td width=\"137\">image_flip()</td>\n<td width=\"439\">Rotates an image on a horizontal axis</td>\n</tr>\n<tr>\n<td width=\"137\">image_flop()</td>\n<td width=\"439\">Rotates an image on a vertical axis</td>\n</tr>\n<tr>\n<td width=\"137\">image_annotate()</td>\n<td width=\"439\">Adds text to an image</td>\n</tr>\n<tr>\n<td width=\"137\">image_background()</td>\n<td width=\"439\">Sets the background for an image</td>\n</tr>\n<tr>\n<td width=\"137\">image_composite()</td>\n<td width=\"439\">Combines images</td>\n</tr>\n<tr>\n<td width=\"137\">image_morph()</td>\n<td width=\"439\">Makes one image appear to gradually become (morph into) another</td>\n</tr>\n<tr>\n<td width=\"137\">image_animate()</td>\n<td width=\"439\">Puts an animation into the RStudio Viewer window</td>\n</tr>\n<tr>\n<td width=\"137\">image_apply()</td>\n<td width=\"439\">Applies a function to every frame in an animated GIF</td>\n</tr>\n<tr>\n<td width=\"137\">image_write()</td>\n<td width=\"439\">Saves an animation as a reusable GIF</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n"}],"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2023-01-10T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":296643},{"headers":{"creationTime":"2016-03-27T16:47:06+00:00","modifiedTime":"2022-07-29T15:15:34+00:00","timestamp":"2022-09-14T18:19:49+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"R","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"},"slug":"r","categoryId":33607}],"title":"R For Dummies Cheat Sheet","strippedTitle":"r for dummies cheat sheet","slug":"r-for-dummies-cheat-sheet","canonicalUrl":"","seo":{"metaDescription":"As you're learning the R programming language, keep this quick reference for how to find R Help files and ways to import data.","noIndex":0,"noFollow":0},"content":"R is more than just a statistical programming language. It’s also a powerful tool for all kinds of data processing and manipulation, used by a community of programmers and users, academics, and practitioners.\r\n\r\nTo get the most out of R, you need to know how to access the R Help files and find help from other sources. To represent data in R, you need to be able to succinctly and correctly specify subsets of your data. Finally, R has many functions that allow you to import data from other applications.","description":"R is more than just a statistical programming language. It’s also a powerful tool for all kinds of data processing and manipulation, used by a community of programmers and users, academics, and practitioners.\r\n\r\nTo get the most out of R, you need to know how to access the R Help files and find help from other sources. To represent data in R, you need to be able to succinctly and correctly specify subsets of your data. Finally, R has many functions that allow you to import data from other applications.","blurb":"","authors":[{"authorId":9088,"name":"Andrie de Vries","slug":"andrie-de-vries","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9088"}},{"authorId":9089,"name":"Joris Meys","slug":"joris-meys","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9089"}}],"primaryCategoryTaxonomy":{"categoryId":33607,"title":"R","slug":"r","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":175059,"title":"How to Create a Data Frame from Scratch in R","slug":"how-to-create-a-data-frame-from-scratch-in-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/175059"}},{"articleId":142864,"title":"Importing Data into R","slug":"importing-data-into-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142864"}},{"articleId":142860,"title":"10 Online Resources for R Programming","slug":"10-online-resources-for-r-programming","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142860"}},{"articleId":142857,"title":"Subsetting R Objects","slug":"subsetting-r-objects","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142857"}},{"articleId":142856,"title":"Getting Help with R","slug":"getting-help-with-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142856"}}],"fromCategory":[{"articleId":262959,"title":"Statistical Analysis with R For Dummies Cheat Sheet","slug":"statistical-analysis-with-r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262959"}},{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281846,"slug":"r-for-dummies-2nd-edition","isbn":"9781119055808","categoryList":["technology","programming-web-design","r"],"amazon":{"default":"https://www.amazon.com/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119055806-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/r-for-dummies-2nd-edition-cover-9781119055808-203x255.jpg","width":203,"height":255},"title":"R For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9088\">Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b data-author-id=\"9089\">Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio-Engineering at the University of Ghent. </p>","authors":[{"authorId":9088,"name":"Andrie de Vries","slug":"andrie-de-vries","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9088"}},{"authorId":9089,"name":"Joris Meys","slug":"joris-meys","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9089"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119055808&quot;]}]\" id=\"du-slot-63221b45ca136\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119055808&quot;]}]\" id=\"du-slot-63221b45cac44\"></div></div>"},"articleType":{"articleType":"Cheat Sheet","articleList":[{"articleId":142856,"title":"Getting Help with R","slug":"getting-help-with-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142856"}},{"articleId":142864,"title":"Importing Data into R","slug":"importing-data-into-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142864"}}],"content":[{"title":"Getting help with R","thumb":null,"image":null,"content":"<p>Even with good introductory books on R, you&#8217;ll need to use the R Help files. The R Help files provide detailed information about the use of different functions and their peculiarities. R has excellent built-in help for every function that explains how to use that function. Just about every Help page has some examples that demonstrate how to use that function.</p>\n<p>To search through the Help files, you&#8217;ll use one of the following functions:</p>\n<ul class=\"level-one\">\n<li>\n<p class=\"first-para\"><span class=\"code\">?:</span> Displays the Help file for a specific function. For example, <span class=\"code\">?data.frame</span> displays the Help file for the <span class=\"code\">data.frame()</span> function.</p>\n</li>\n<li>\n<p class=\"first-para\"><span class=\"code\">??:</span> Searches for a word (or pattern) in the Help files. For example, <span class=\"code\">??list</span> returns the names of functions that contain the word list in either the function names or their descriptions.</p>\n</li>\n<li>\n<p class=\"first-para\"><span class=\"code\">RSiteSearch():</span> Performs an online search of <a href=\"http://search.r-project.org/nmz.html\" target=\"_blank\" rel=\"noopener\"><b>RSiteSearch</b></a>. This search engine allows you to perform a search of the R functions, package vignettes and the R-help mail archives. For example, <span class=\"code\">RSiteSearch(</span><span class=\"code\">&#8220;</span><span class=\"code\">linear models</span><span class=\"code\">&#8220;</span><span class=\"code\">)</span> does a search at this website for the search term &#8220;linear models.&#8221;</p>\n</li>\n</ul>\n<p>You aren&#8217;t limited to the R Help files if you&#8217;re looking for help with R. The add-on package <span class=\"code\">sos</span>, available for download from CRAN <a href=\"http://cran.r-project.org/web/packages/sos/index.html\" target=\"_blank\" rel=\"noopener\"><b>here</b></a>, has some neat functions to search all the Help files on <a href=\"http://search.r-project.org/nmz.html\" target=\"_blank\" rel=\"noopener\"><b>RSiteSearch</b></a>. It displays results in a web browser window, making it easy to work with.</p>\n<p>To use the package <span class=\"code\">sos</span>, you need to install the package by typing <b>install.packages(</b><b>&#8220;</b><b>sos</b><b>&#8220;</b><b>)</b> in your R console, and then load the package with <span class=\"code\">library(</span><span class=\"code\">&#8220;</span><span class=\"code\">sos</span><span class=\"code\">&#8220;</span><span class=\"code\">)</span>.</p>\n<p>Then you can use the <span class=\"code\">findFn()</span> function to do your search. For example, by typing <b>findFn(</b><b>&#8220;</b><b>regression</b><b>&#8220;</b><b>)</b> into your R console, you get a web page with the names, descriptions and links to several hundred functions that contain the word <i>regression</i> in the function name or Help text description.</p>\n"},{"title":"Importing data into R","thumb":null,"image":null,"content":"<p>R has many functions that allow you to import data from other applications. The following table lists some of the useful text import functions, what they do, and examples of how to use them.</p>\n<table>\n<tbody>\n<tr>\n<th>Function</th>\n<th>What It Does</th>\n<th>Example</th>\n</tr>\n<tr>\n<td><span class=\"code\">read.table()</span></td>\n<td>Reads any tabular data where the columns are separated (for<br />\nexample by commas or tabs). You can specify the separator (for<br />\nexample, commas or tabs), as well as other arguments to precisely<br />\ndescribe your data.</td>\n<td><span class=\"code\">read.table(file=&#8221;myfile&#8221;, sep=&#8221;t&#8221;,<br />\nheader=TRUE)</span></td>\n</tr>\n<tr>\n<td><span class=\"code\">read.csv()</span></td>\n<td>A simplified version of <span class=\"code\">read.table</span><span class=\"code\">()</span> with all<br />\nthe arguments preset to read CSV files, like Microsoft Excel<br />\nspreadsheets.</td>\n<td><span class=\"code\">read.csv(file=&#8221;myfile&#8221;)</span></td>\n</tr>\n<tr>\n<td><span class=\"code\">read.csv2()</span></td>\n<td>A version of <span class=\"code\">read.csv()</span> configured<br />\nfor data with a comma as the decimal point and a semicolon as the<br />\nfield separator.</td>\n<td><span class=\"code\">read.csv2(file=&#8221;myfile&#8221;,<br />\nheader=TRUE)</span></td>\n</tr>\n<tr>\n<td><span class=\"code\">read.delim()</span></td>\n<td>Useful for reading delimited files, with tabs as the default<br />\nseparator.</td>\n<td><span class=\"code\">read.delim(file=&#8221;myfile&#8221;,<br />\nheader=TRUE)</span></td>\n</tr>\n<tr>\n<td><span class=\"code\">scan()</span></td>\n<td>Allows you finer control over the read process when your data<br />\nisn’t tabular.</td>\n<td><span class=\"code\">scan(&#8220;myfile&#8221;, skip = 1,<br />\nnmax=100)</span></td>\n</tr>\n<tr>\n<td><span class=\"code\">readLines()</span></td>\n<td>Reads text from a text file one line at a time.</td>\n<td><span class=\"code\">readLines(&#8220;myfile&#8221;)</span></td>\n</tr>\n<tr>\n<td><span class=\"code\">read.fwf</span></td>\n<td>Read a file with dates in fixed-width format. In other words,<br />\neach column in the data has a fixed number of characters.</td>\n<td><span class=\"code\">read.fwf(&#8220;myfile&#8221;,<br />\nwidths=c(1,2,3)</span></td>\n</tr>\n</tbody>\n</table>\n<p>In addition to these options to read text data, the package <span class=\"code\">foreign</span> allows you to read data from other popular statistical formats, such as SPSS. To use these functions, you first have to load the built-in <span class=\"code\">foreign</span> package, with the following command:</p>\n<pre class=\"code\">&gt; library(\"foreign\")</pre>\n<p>The following table lists the functions to import data from SPSS, Stata, and SAS.</p>\n<table>\n<tbody>\n<tr>\n<th>Function</th>\n<th>What It Does</th>\n<th>Example</th>\n</tr>\n<tr>\n<td><span class=\"code\">read.spss</span></td>\n<td>Reads SPSS data file</td>\n<td><span class=\"code\">read.spss(&#8220;myfile&#8221;)</span></td>\n</tr>\n<tr>\n<td><span class=\"code\">read.dta</span></td>\n<td>Reads Stata binary file</td>\n<td><span class=\"code\">read.dta(&#8220;myfile&#8221;)</span></td>\n</tr>\n<tr>\n<td><span class=\"code\">read.xport</span></td>\n<td>Reads SAS export file</td>\n<td><span class=\"code\">read.export(&#8220;myfile&#8221;)</span></td>\n</tr>\n</tbody>\n</table>\n"}],"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2022-02-14T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":207492},{"headers":{"creationTime":"2018-03-02T18:53:33+00:00","modifiedTime":"2022-05-02T14:14:35+00:00","timestamp":"2022-09-14T18:19:42+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"R","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"},"slug":"r","categoryId":33607}],"title":"R Projects For Dummies Cheat Sheet","strippedTitle":"r projects for dummies cheat sheet","slug":"r-projects-dummies-cheat-sheet","canonicalUrl":"","seo":{"metaDescription":"Keep this Cheat Sheet nearby when working in R for quick reference to functions for users, machine learning, databases, maps, and more.","noIndex":0,"noFollow":0},"content":"To complete any project using R, you work with functions that live in packages designed for specific areas. This cheat sheet provides some information about these functions.","description":"To complete any project using R, you work with functions that live in packages designed for specific areas. This cheat sheet provides some information about these functions.","blurb":"","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"primaryCategoryTaxonomy":{"categoryId":33607,"title":"R","slug":"r","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}},{"articleId":251653,"title":"R Project for Neural Networks: Rattling Around","slug":"r-project-neural-networks-rattling-around","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251653"}}],"fromCategory":[{"articleId":262959,"title":"Statistical Analysis with R For Dummies Cheat Sheet","slug":"statistical-analysis-with-r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262959"}},{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281847,"slug":"r-projects-for-dummies","isbn":"9781119446187","categoryList":["technology","programming-web-design","r"],"amazon":{"default":"https://www.amazon.com/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/111944618X-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/r-projects-for-dummies-cover-9781119446187-203x255.jpg","width":203,"height":255},"title":"R Projects For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9759\">Joseph Schmuller, PhD,</b> is a veteran of more than 25 years in Information Technology. He is the author of several books, including <i>Statistical Analysis with R For Dummies</i> and four editions of <i>Statistical Analysis with Excel For Dummies.</i> In addition, he has written numerous articles and created online coursework for Lynda.com. </p>","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119446187&quot;]}]\" id=\"du-slot-63221b3e35f24\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119446187&quot;]}]\" id=\"du-slot-63221b3e3697d\"></div></div>"},"articleType":{"articleType":"Cheat Sheet","articleList":[{"articleId":250440,"title":"Interacting with Users with R Functions","slug":"interacting-users-r-functions","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/250440"}},{"articleId":250443,"title":"Tackling Machine Learning with R","slug":"tackling-machine-learning-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/250443"}},{"articleId":250446,"title":"Working with Large(ish) Databases in R","slug":"working-largeish-databases-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/250446"}},{"articleId":250449,"title":"Manipulating Maps and Images with R","slug":"manipulating-maps-images-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/250449"}}],"content":[{"title":"Interacting with users with R functions","thumb":null,"image":null,"content":"<p>Here&#8217;s a selection of statistical functions that come with the standard R installation. You&#8217;ll find many others in R packages. R provides the <code>shiny </code>package and the <code>shinydashboard </code>package for developing interactive applications. Here are selected functions from these packages:</p>\n<table width=\"648\">\n<caption><strong>Central Tendency and Variability</strong></caption>\n<tbody>\n<tr>\n<td width=\"144\"><strong>Function</strong></td>\n<td width=\"388\"><strong>What it Calculates</strong></td>\n</tr>\n<tr>\n<td width=\"144\"><code>mean(x)</code></td>\n<td width=\"388\">Mean of the numbers in vector x.</td>\n</tr>\n<tr>\n<td width=\"144\"><code>median(x)</code></td>\n<td width=\"388\">Median of the numbers in vector x</td>\n</tr>\n<tr>\n<td width=\"144\"><code>var(x)</code></td>\n<td width=\"388\">Estimated variance of the population from which the numbers in vector x are sampled</td>\n</tr>\n<tr>\n<td width=\"144\"><code>sd(x)</code></td>\n<td width=\"388\">Estimated standard deviation of the population from which the numbers in vector x are sampled</td>\n</tr>\n<tr>\n<td width=\"144\"><code>scale(x)</code></td>\n<td width=\"388\">Standard scores (z-scores) for the numbers in vector x</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n<p><strong>Relative Standing</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"266\"><strong>Function</strong></td>\n<td width=\"266\"><strong>What it Calculates</strong></td>\n</tr>\n<tr>\n<td width=\"266\"><code>sort(x)</code></td>\n<td width=\"266\">The numbers in vector x in increasing order</td>\n</tr>\n<tr>\n<td width=\"266\"><code>sort(x)[n]</code></td>\n<td width=\"266\">The nth smallest number in vector x</td>\n</tr>\n<tr>\n<td width=\"266\"><code>rank(x)</code></td>\n<td width=\"266\">Ranks of the numbers (in increasing order) in vector x</td>\n</tr>\n<tr>\n<td width=\"266\"><code>rank(-x)</code></td>\n<td width=\"266\">Ranks of the numbers (in decreasing order) in vector x</td>\n</tr>\n<tr>\n<td width=\"266\"><code>rank(x, ties.method= \"average\")</code></td>\n<td width=\"266\">Ranks of the numbers (in increasing order) in vector x, with tied numbers given the average of the ranks that the ties would have attained</td>\n</tr>\n<tr>\n<td width=\"266\"><code>rank(x, ties.method=  \"min\")</code></td>\n<td width=\"266\">Ranks of the numbers (in increasing order) in vector x, with tied numbers given the minimum of the ranks that the ties would have attained</td>\n</tr>\n<tr>\n<td width=\"266\"><code>rank(x, ties.method = \"max\")</code></td>\n<td width=\"266\">Ranks of the numbers (in increasing order) in vector x, with tied numbers given the maximum of the ranks that the ties would have attained</td>\n</tr>\n<tr>\n<td width=\"266\"><code>quantile(x)</code></td>\n<td width=\"266\">The 0th, 25th, 50th, 75th, and 100th percentiles (i.e, the <em>quartiles</em>) of the numbers in vector x. (That’s not a misprint: quantile(x) returns the quartiles of x.)</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n<p><strong>T-tests</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"184\"><strong>Function</strong></td>\n<td width=\"348\"><strong>What it Calculates</strong></td>\n</tr>\n<tr>\n<td width=\"184\"><code>t.test(x,mu=n, alternative = \"two.sided\")</code></td>\n<td width=\"348\">Two-tailed t-test that the mean of the numbers in vector x is different from n.</td>\n</tr>\n<tr>\n<td width=\"184\"><code>t.test(x,mu=n, alternative = \"greater\")</code></td>\n<td width=\"348\">One-tailed t-test that the mean of the numbers in vector x is greater than n.</td>\n</tr>\n<tr>\n<td width=\"184\"><code>t.test(x,mu=n, alternative = \"less\")</code></td>\n<td width=\"348\">One-tailed t-test that the mean of the numbers in vector x is less than n.</td>\n</tr>\n<tr>\n<td width=\"184\"><code>t.test(x,y,mu=0, var.equal  = TRUE, alternative = \"two.sided\")</code></td>\n<td width=\"348\">Two-tailed t-test that the mean of the numbers in vector x is different from the mean of the numbers in vector y. The variances in the two vectors are assumed to be equal.</td>\n</tr>\n<tr>\n<td width=\"184\"><code>t.test(x,y,mu=0, alternative = \"two.sided\", paired  = TRUE)</code></td>\n<td width=\"348\">Two-tailed t-test that the mean of the numbers in vector x is different from the mean of the numbers in vector y. The vectors represent matched samples.</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n<p><strong>Analysis of Variance (ANOVA)</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"136\"><strong>Function</strong></td>\n<td width=\"396\"><strong>What it Calculates</strong></td>\n</tr>\n<tr>\n<td width=\"136\"><code>aov(y~x, data = d)</code></td>\n<td width=\"396\">Single-factor ANOVA, with the numbers in vector y as the dependent variable and the elements of vector x as the levels of the independent variable. The data are in data frame d.</td>\n</tr>\n<tr>\n<td width=\"136\"><code>aov(y~x + Error(w/x), data = d)</code></td>\n<td width=\"396\">Repeated Measures ANOVA, with the numbers in vector y as the dependent variable and the elements in vector x as the levels of an independent variable. Error(w/x) indicates that each element in vector w experiences all the levels of x (i.e., x is a repeated measure). The data are in data frame d.</td>\n</tr>\n<tr>\n<td width=\"136\"><code>aov(y~x*z, data = d)</code></td>\n<td width=\"396\">Two-factor ANOVA, with the numbers in vector y as the dependent variable and the elements of vectors x and z as the levels of the two independent variables. The data are in data frame d.</td>\n</tr>\n<tr>\n<td width=\"136\"><code>aov(y~x*z + Error(w/z), data = d)</code></td>\n<td width=\"396\">Mixed ANOVA, with the numbers in vector z as the dependent variable and the elements of vectors x and y as the levels of the two independent variables. Error(w/z) indicates that each element in vector w experiences all the levels of z (i.e., z is a repeated measure). The data are in data frame d.</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n<p><strong>Correlation and Regression</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"174\"><strong>Function</strong></td>\n<td width=\"357\"><strong>What it Calculates</strong></td>\n</tr>\n<tr>\n<td width=\"174\"><code>cor(x,y)</code></td>\n<td width=\"357\">Correlation coefficient between the numbers in vector x and the numbers in vector y</td>\n</tr>\n<tr>\n<td width=\"174\"><code>cor.test(x,y)</code></td>\n<td width=\"357\">Correlation coefficient between the numbers in vector x and the numbers in vector y, along with a t-test of the significance of the correlation coefficient.</td>\n</tr>\n<tr>\n<td width=\"174\"><code>lm(y~x, data = d)</code></td>\n<td width=\"357\">Linear regression analysis with the numbers in vector y as the dependent variable and the numbers in vector x as the independent variable. Data are in data frame d.</td>\n</tr>\n<tr>\n<td width=\"174\"><code>coefficients(a)</code></td>\n<td width=\"357\">Slope and intercept of linear regression model a.</td>\n</tr>\n<tr>\n<td width=\"174\"><code>confint(a)</code></td>\n<td width=\"357\">Confidence intervals of the slope and intercept of linear regression model a</td>\n</tr>\n<tr>\n<td width=\"174\"><code>lm(y~x+z, data = d)</code></td>\n<td width=\"357\">Multiple regression analysis with the numbers in vector y as the dependent variable and the numbers in vectors x and z as the independent variables. Data are in data frame d.</td>\n</tr>\n</tbody>\n</table>\n<p class=\"article-tips tip\">When you carry out an ANOVA or a regression analysis, store the analysis in a list.</p>\n<p>For example, <code>a &lt;- lm(y~x, data = d)</code>.</p>\n<p>Then, to see the tabled results, use the <code>summary()</code> function:</p>\n<p><code>summary(a)</code></p>\n"},{"title":"Tackling machine learning with R","thumb":null,"image":null,"content":"<p>Machine Learning (ML) is a popular area. R provides a number of ML-related packages and functions. Here are some of them:</p>\n<p><strong>Machine Learning Packages and Functions</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"109\"><strong>Package</strong></td>\n<td width=\"142\"><strong>Function</strong></td>\n<td width=\"281\"><strong>What it does</strong></td>\n</tr>\n<tr>\n<td width=\"109\"><code>rattle</code></td>\n<td width=\"142\"><code>rattle()</code></td>\n<td width=\"281\">Opens the Rattle Graphic User Interface</td>\n</tr>\n<tr>\n<td width=\"109\"><code>rpart</code></td>\n<td width=\"142\"><code>rpart()</code></td>\n<td width=\"281\">Creates a decision tree</td>\n</tr>\n<tr>\n<td width=\"109\"><code>rpart.plot</code></td>\n<td width=\"142\"><code>prp()</code></td>\n<td width=\"281\">Draws a decision tree</td>\n</tr>\n<tr>\n<td width=\"109\"><code>randomForest</code></td>\n<td width=\"142\"><code>randomForest()</code></td>\n<td width=\"281\">Creates a random forest of decision trees</td>\n</tr>\n<tr>\n<td width=\"109\"><code>rattle</code></td>\n<td width=\"142\"><code>printRandomForests()</code></td>\n<td width=\"281\">Prints the rules of a forest’s individual decision trees</td>\n</tr>\n<tr>\n<td width=\"109\"><code>e1071</code></td>\n<td width=\"142\"><code>svm()</code></td>\n<td width=\"281\">Trains a support vector machine</td>\n</tr>\n<tr>\n<td width=\"109\"><code>e1071</code></td>\n<td width=\"142\"><code>predict()</code></td>\n<td width=\"281\">Creates a vector of predicted classifications based on a support vector machine</td>\n</tr>\n<tr>\n<td width=\"109\"><code>kernlab</code></td>\n<td width=\"142\"><code>ksvm()</code></td>\n<td width=\"281\">Trains a support vector machine</td>\n</tr>\n<tr>\n<td width=\"109\"><code>base R</code></td>\n<td width=\"142\"><code>kmeans()</code></td>\n<td width=\"281\">Creates a k-means clustering analysis</td>\n</tr>\n<tr>\n<td width=\"109\"><code>nnet</code></td>\n<td width=\"142\"><code>nnet()</code></td>\n<td width=\"281\">Creates a neural network with one hidden layer</td>\n</tr>\n<tr>\n<td width=\"109\"><code>NeuralNetTools</code></td>\n<td width=\"142\"><code>plotnet()</code></td>\n<td width=\"281\">Draws a neural network</td>\n</tr>\n<tr>\n<td width=\"109\"><code>nnet</code></td>\n<td width=\"142\"><code>predict()</code></td>\n<td width=\"281\">Creates a vector of predictions based on a neural network</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n"},{"title":"Working with large(ish) databases in R","thumb":null,"image":null,"content":"<p>Created for statistical analysis, R has a wide array of packages and functions for dealing with large amounts of data. This selection is the tip of the iceberg’s tip:</p>\n<p><strong>Packages and Functions for Exploring Databases</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"93\"><strong>Package</strong></td>\n<td width=\"140\"><strong>Function</strong></td>\n<td width=\"299\"><strong>What it does</strong></td>\n</tr>\n<tr>\n<td width=\"93\"><code>didrooRFM</code></td>\n<td width=\"140\"><code>findRFM()</code></td>\n<td width=\"299\">Performs a Recency, Frequency, Money analysis on a database of retail transactions</td>\n</tr>\n<tr>\n<td width=\"93\"><code>vcd</code></td>\n<td width=\"140\"><code>assocstats()</code></td>\n<td width=\"299\">Calculates statistics for tables of categorical data</td>\n</tr>\n<tr>\n<td width=\"93\"><code>vcd</code></td>\n<td width=\"140\"><code>assoc()</code></td>\n<td width=\"299\">Creates a graphic that shows deviations from independence in a table of categorical data</td>\n</tr>\n<tr>\n<td width=\"93\"><code>tidyverse</code></td>\n<td width=\"140\"><code>glimpse()</code></td>\n<td width=\"299\">Provides a partial view of a data frame with the columns appearing onscreen as rows</td>\n</tr>\n<tr>\n<td width=\"93\"><code>plotrix</code></td>\n<td width=\"140\"><code>std.error()</code></td>\n<td width=\"299\">Calculates the standard error of the mean</td>\n</tr>\n<tr>\n<td width=\"93\"><code>plyr</code></td>\n<td width=\"140\"><code>inner_join()</code></td>\n<td width=\"299\">Joins data frames</td>\n</tr>\n<tr>\n<td width=\"93\"><code>lubridate</code></td>\n<td width=\"140\"><code>wday()</code></td>\n<td width=\"299\">Returns day of the week of a calendar date</td>\n</tr>\n<tr>\n<td width=\"93\"><code>lubridate</code></td>\n<td width=\"140\"><code>ymd()</code></td>\n<td width=\"299\">Returns a date in R date-format</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"Manipulating maps and images with R","thumb":null,"image":null,"content":"<p>Here are some packages and functions to help you get started using R to draw maps and to process images.</p>\n<p><strong>Packages and Functions for Plotting Maps and for Processing Images</strong></p>\n<table>\n<tbody>\n<tr>\n<td width=\"177\"><strong>Package</strong></td>\n<td width=\"177\"><strong>Function</strong></td>\n<td width=\"177\"><strong>What it does</strong></td>\n</tr>\n<tr>\n<td width=\"177\"><code>maps</code></td>\n<td width=\"177\"><code>map_data()</code></td>\n<td width=\"177\">Returns a data frame of latitudes and longitudes</td>\n</tr>\n<tr>\n<td width=\"177\"><code>ggmaps</code></td>\n<td width=\"177\"><code>geocode()</code></td>\n<td width=\"177\">Returns latitude and longitude of a place-name</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_read()</code></td>\n<td width=\"177\">Reads an image into R and turns it into a magick object</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_resize()</code></td>\n<td width=\"177\">Resizes an image</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_rotate()</code></td>\n<td width=\"177\">Rotates an image</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_flip()</code></td>\n<td width=\"177\">Rotates an image on a horizontal axis</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_flop()</code></td>\n<td width=\"177\">Rotates an image on a vertical axis</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_annotate()</code></td>\n<td width=\"177\">Adds text to an image</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_background()</code></td>\n<td width=\"177\">Sets the background for an image</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_composite()</code></td>\n<td width=\"177\">Combines images</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_morph()</code></td>\n<td width=\"177\">Makes one image appear to gradually become (morph into) another</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_animate()</code></td>\n<td width=\"177\">Puts an animation into the RStudio Viewer window</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_apply()</code></td>\n<td width=\"177\">Applies a function to every frame in an animated GIF</td>\n</tr>\n<tr>\n<td width=\"177\"><code>magick</code></td>\n<td width=\"177\"><code>image_write()</code></td>\n<td width=\"177\">Saves an animation as a reusable GIF</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n"}],"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2022-05-02T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":250453},{"headers":{"creationTime":"2019-07-24T15:34:08+00:00","modifiedTime":"2022-01-26T21:23:16+00:00","timestamp":"2022-09-14T18:19:03+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"R","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"},"slug":"r","categoryId":33607}],"title":"Statistical Analysis with R For Dummies Cheat Sheet","strippedTitle":"statistical analysis with r for dummies cheat sheet","slug":"statistical-analysis-with-r-for-dummies-cheat-sheet","canonicalUrl":"","seo":{"metaDescription":"Find out about the wide array of functions R provides to help you with statistical analysis, from simple statistics to complex analyses.","noIndex":0,"noFollow":0},"content":"R provides a wide array of functions to help you with <a href=\"https://www.dummies.com/programming/big-data/data-science/basics-of-r-programming-for-predictive-analytics/\" target=\"_blank\" rel=\"noopener\">statistical analysis with R</a>—from simple statistics to complex analyses. Several statistical functions are built into R and R packages. R statistical functions fall into several categories including central tendency and variability, relative standing, t-tests, analysis of variance and regression analysis.","description":"R provides a wide array of functions to help you with <a href=\"https://www.dummies.com/programming/big-data/data-science/basics-of-r-programming-for-predictive-analytics/\" target=\"_blank\" rel=\"noopener\">statistical analysis with R</a>—from simple statistics to complex analyses. Several statistical functions are built into R and R packages. R statistical functions fall into several categories including central tendency and variability, relative standing, t-tests, analysis of variance and regression analysis.","blurb":"","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"primaryCategoryTaxonomy":{"categoryId":33607,"title":"R","slug":"r","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":241780,"title":"Testing a Variance in R","slug":"testing-variance-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241780"}},{"articleId":241777,"title":"Plotting t in ggplot2","slug":"plotting-t-ggplot2","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241777"}},{"articleId":241774,"title":"Plotting t in Base R Graphics","slug":"plotting-t-base-r-graphics","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241774"}},{"articleId":241770,"title":"Z Testing in R","slug":"z-testing-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241770"}},{"articleId":241767,"title":"The Standard Normal Distribution in R","slug":"standard-normal-distribution-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241767"}}],"fromCategory":[{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}},{"articleId":251653,"title":"R Project for Neural Networks: Rattling Around","slug":"r-project-neural-networks-rattling-around","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251653"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281874,"slug":"statistical-analysis-with-r-for-dummies","isbn":"9781119337065","categoryList":["technology","programming-web-design","r"],"amazon":{"default":"https://www.amazon.com/gp/product/1119337062/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119337062/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119337062-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119337062/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119337062/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/statistical-analysis-with-r-for-dummies-cover-9781119337065-203x255.jpg","width":203,"height":255},"title":"Statistical Analysis with R For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9759\">Joseph Schmuller, PhD,</b> has taught undergraduate and graduate statistics, and has 25 years of IT experience. The author of four editions of <i>Statistical Analysis with Excel For Dummies</i> and three editions of <i>Teach Yourself UML in 24 Hours</i> (SAMS), he has created online coursework for Lynda.com and is a former Editor in Chief of <i>PC AI</i> magazine. He is a Research Scholar at the University of North Florida. </p>","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119337065&quot;]}]\" id=\"du-slot-63221b17db920\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119337065&quot;]}]\" id=\"du-slot-63221b17dc2da\"></div></div>"},"articleType":{"articleType":"Cheat Sheet","articleList":[{"articleId":262961,"title":"Base R Statistical Functions for Central Tendency and Variability","slug":"","categoryList":[],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262961"}},{"articleId":262964,"title":"Base R Statistical Functions for Relative Standing","slug":"","categoryList":[],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262964"}},{"articleId":262967,"title":"T-Test Functions for Statistical Analysis with R","slug":"","categoryList":[],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262967"}},{"articleId":262970,"title":"ANOVA and Regression Analysis Functions for Statistical Analysis with R","slug":"","categoryList":[],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262970"}}],"content":[{"title":"Base R statistical functions for central tendency and variability","thumb":null,"image":null,"content":"<p>Here&#8217;s a selection of statistical functions having to do with central tendency and variability that come with the standard R installation. You’ll find many others in R packages.</p>\n<p>Each of these statistical functions consists of a function name immediately followed by parentheses, such as <code>mean()</code>, and <code>var()</code>. Inside the parentheses are the arguments. In this context, “argument” doesn’t mean “disagreement,” “confrontation,” or anything like that. It’s just the math term for whatever a function operates on.</p>\n<table width=\"644\">\n<tbody>\n<tr>\n<td width=\"159\"><strong>Function</strong></td>\n<td width=\"412\"><strong>What it Calculates</strong></td>\n<td width=\"65\"></td>\n</tr>\n<tr>\n<td width=\"159\"><code>mean(<em>x</em>)</code></td>\n<td colspan=\"2\" width=\"479\">Mean of the numbers in vector x.</td>\n</tr>\n<tr>\n<td width=\"159\"><code>median(<em>x</em>)</code></td>\n<td colspan=\"2\" width=\"479\">Median of the numbers in vector x</td>\n</tr>\n<tr>\n<td width=\"159\"><code>var(<em>x</em>)</code></td>\n<td colspan=\"2\" width=\"479\">Estimated variance of the population from which the numbers in vector x are sampled</td>\n</tr>\n<tr>\n<td width=\"159\"><code>sd(<em>x</em>)</code></td>\n<td colspan=\"2\" width=\"479\">Estimated standard deviation of the population from which the numbers in vector x are sampled</td>\n</tr>\n<tr>\n<td width=\"159\"><code>scale(<em>x</em>)</code></td>\n<td colspan=\"2\" width=\"479\">Standard scores (z-scores) for the numbers in vector x</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"Base R Statistical Functions for Relative Standing","thumb":null,"image":null,"content":"<p>Here&#8217;s a selection of R statistical functions having to do with relative standing.</p>\n<table>\n<tbody>\n<tr>\n<td>F<strong>unction</strong></td>\n<td><strong>What it Calculates</strong></td>\n</tr>\n<tr>\n<td><code>sort(x)</code></td>\n<td>The numbers in vector x in increasing order</td>\n</tr>\n<tr>\n<td><code>sort(x)[n]</code></td>\n<td>The nth smallest number in vector x</td>\n</tr>\n<tr>\n<td><code>rank(x)</code></td>\n<td>Ranks of the numbers (in increasing order) in vector x</td>\n</tr>\n<tr>\n<td><code>rank(-x)</code></td>\n<td>Ranks of the numbers (in decreasing order) in vector x</td>\n</tr>\n<tr>\n<td><code>rank(x, ties.method= “average”)</code></td>\n<td>Ranks of the numbers (in increasing order) in vector x, with tied numbers given the average of the ranks that the ties would have attained</td>\n</tr>\n<tr>\n<td>\n<table>\n<tbody>\n<tr>\n<td><code>rank(x, ties.method=  “min”)</code></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n</td>\n<td>Ranks of the numbers (in increasing order) in vector x, with tied numbers given the minimum of the ranks that the ties would have attained</td>\n</tr>\n<tr>\n<td><code>rank(x, ties.method = “max”)</code></td>\n<td>Ranks of the numbers (in increasing order) in vector x, with tied numbers given the maximum of the ranks that the ties would have attained</td>\n</tr>\n<tr>\n<td><code>quantile(x)</code></td>\n<td>The 0<sup>th</sup>, 25<sup>th</sup>, 50<sup>th</sup>, 75<sup>th</sup>, and 100<sup>th</sup> percentiles (i.e, the <em>quartiles</em>) of the numbers in vector x. (That’s not a misprint: quantile(x) returns the quartiles of x.)</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"T-Test Functions for Statistical Analysis with R","thumb":null,"image":null,"content":"<p>Here&#8217;s a selection of R statistical functions having to do with t-tests.</p>\n<table>\n<tbody>\n<tr>\n<td><strong>Function</strong></td>\n<td><strong>What it Calculates</strong></td>\n</tr>\n<tr>\n<td><code>t.test(x,mu=n, alternative = “two.sided”)</code></td>\n<td>Two-tailed t-test that the mean of the numbers in vector x is different from n.</td>\n</tr>\n<tr>\n<td><code>t.test(x,mu=n, alternative = “greater”)</code></td>\n<td>One-tailed t-test that the mean of the numbers in vector x is greater than n.</td>\n</tr>\n<tr>\n<td><code>t.test(x,mu=n, alternative = “less”)</code></td>\n<td>One-tailed t-test that the mean of the numbers in vector x is less than n.</td>\n</tr>\n<tr>\n<td><code>t.test(x,y,mu=0, var.equal  = TRUE, alternative = “two.sided”)</code></td>\n<td>Two-tailed t-test that the mean of the numbers in vector x is different from the mean of the numbers in vector y. The variances in the two vectors are assumed to be equal.</td>\n</tr>\n<tr>\n<td><code>t.test(x,y,mu=0, alternative = “two.sided”, paired  = TRUE)</code></td>\n<td>Two-tailed t-test that the mean of the numbers in vector x is different from the mean of the numbers in vector y. The vectors represent matched samples.</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"ANOVA and Regression Analysis Functions for Statistical Analysis with R","thumb":null,"image":null,"content":"<p>Here&#8217;s a selection of R statistical functions having to do with Analysis of Variance (ANOVA) and correlation and regression.</p>\n<p>When you carry out an ANOVA or a regression analysis, store the analysis in a list. For example,</p>\n<p><code>a &lt;- lm(y~x, data = d)</code></p>\n<p>Then, to see the tabled results, use the summary() function:</p>\n<p><code>summary(a)</code></p>\n<table>\n<caption><strong>Analysis of Variance (ANOVA)</strong></caption>\n<tbody>\n<tr>\n<td><strong>Function</strong></td>\n<td><strong>What it Calculates</strong></td>\n</tr>\n<tr>\n<td><code>aov(y~x, data = d)</code></td>\n<td>Single-factor ANOVA, with the numbers in vector y as the dependent variable and the elements of vector x as the levels of the independent variable. The data are in data frame <em>d</em>.</td>\n</tr>\n<tr>\n<td><code>aov(y~x + Error(w/x), data = d)</code></td>\n<td>Repeated Measures ANOVA, with the numbers in vector y as the dependent variable and the elements in vector x as the levels of an independent variable. Error(w/x) indicates that each element in vector w experiences all the levels of <em>x</em> (i.e., <em>x</em> is a repeated measure). The data are in data frame d.</td>\n</tr>\n<tr>\n<td><code>aov(y~x*z, data = d)</code></td>\n<td>Two-factor ANOVA, with the numbers in vector y as the dependent variable and the elements of vectors <em>x</em> and <em>z</em> as the levels of the two independent variables. The data are in data frame <em>d</em>.</td>\n</tr>\n<tr>\n<td><code>aov(y~x*z + Error(w/z), data = d)</code></td>\n<td>Mixed ANOVA, with the numbers in vector z as the dependent variable and the elements of vectors <em>x</em> and <em>y</em> as the levels of the two independent variables. Error(w/z) indicates that each element in vector <em>w</em> experiences all the levels of <em>z</em> (i.e., <em>z</em> is a repeated measure). The data are in data frame <em>d</em>.</td>\n</tr>\n</tbody>\n</table>\n<table>\n<caption><strong>Correlation and Regression</strong></caption>\n<tbody>\n<tr>\n<td><strong>Function</strong></td>\n<td><strong>What it Calculates</strong></td>\n</tr>\n<tr>\n<td><code>cor(x,y)</code></td>\n<td>Correlation coefficient between the numbers in vector <em>x</em> and the numbers in vector <em>y</em></td>\n</tr>\n<tr>\n<td><code>cor.test(x,y)</code></td>\n<td>Correlation coefficient between the numbers in vector <em>x</em> and the numbers in vector <em>y</em>, along with a t-test of the significance of the correlation coefficient.</td>\n</tr>\n<tr>\n<td><code>lm(y~x, data = d)</code></td>\n<td>Linear regression analysis with the numbers in vector <em>y</em> as the dependent variable and the numbers in vector<em> x</em> as the independent variable. Data are in data frame <em>d</em>.</td>\n</tr>\n<tr>\n<td><code>coefficients(a)</code></td>\n<td>Slope and intercept of linear regression model <em>a</em>.</td>\n</tr>\n<tr>\n<td><code>confint(a)</code></td>\n<td>Confidence intervals of the slope and intercept of linear regression model <em>a</em></td>\n</tr>\n<tr>\n<td><code>lm(y~x+z, data = d)</code></td>\n<td>Multiple regression analysis with the numbers in vector y as the dependent variable and the numbers in vectors <em>x</em> and <em>z</em> as the independent variables. Data are in data frame<em> d</em>.</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n"}],"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2022-01-26T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":262959},{"headers":{"creationTime":"2016-03-26T07:31:06+00:00","modifiedTime":"2021-11-04T18:50:43+00:00","timestamp":"2022-09-14T18:18:44+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"R","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"},"slug":"r","categoryId":33607}],"title":"How to Name Matrix Rows and Columns in R programming","strippedTitle":"how to name matrix rows and columns in r programming","slug":"how-to-name-matrix-rows-and-columns-in-r","canonicalUrl":"","seo":{"metaDescription":"In the R programming language, you name the values in a vector, and you can do something very similar with rows and columns in a matrix.","noIndex":0,"noFollow":0},"content":"The <span class=\"code\">rbind()</span> function in the <a href=\"https://www.dummies.com/programming/r/the-benefits-of-using-r/\" target=\"_blank\" rel=\"noopener\">R programming language</a> conveniently adds the names of the vectors to the rows of the matrix. You name the values in a vector, and you can do something very similar with rows and columns in a matrix.\r\n\r\nFor that, you have the functions <span class=\"code\">rownames()</span> and <span class=\"code\">colnames()</span>. Guess which one does what? Both functions work much like the <span class=\"code\">names()</span> function you use when naming vector values.\r\n<h2 id=\"tab1\" >Changing the row and column names</h2>\r\nThe matrix <span class=\"code\">baskets.team</span> already has some row names. It would be better if the names of the rows would just read <span class=\"code\">“</span><span class=\"code\">Granny</span><span class=\"code\">”</span> and <span class=\"code\">“</span><span class=\"code\">Geraldine</span><span class=\"code\">”</span>. You can easily change these row names like this:\r\n<pre class=\"code\">&gt; rownames(baskets.team) &lt;- c(“Granny”, “Geraldine”)</pre>\r\nYou can look at the matrix to check if this did what it’s supposed to do, or you can take a look at the row names itself like this:\r\n<pre class=\"code\">&gt; rownames(baskets.team)\r\n[1] “Granny” “Geraldine”</pre>\r\nThe <span class=\"code\">colnames()</span> function works exactly the same. You can, for example, add the number of the game as a column name using the following code:\r\n<pre class=\"code\">&gt; colnames(baskets.team) &lt;- c(“1st”, “2nd”, “3th”, “4th”, “5th”, “6th”)</pre>\r\nThis gives you the following matrix:\r\n<pre class=\"code\">&gt; baskets.team\r\n 1st 2nd 3th 4th 5th 6th\r\nGranny 12 4 5 6 9 3\r\nGeraldine 5 4 2 4 12 9</pre>\r\nThis is almost like you want it, but the third column name contains an annoying writing mistake. No problem there; R allows you to easily correct that mistake. Just as the with <span class=\"code\">names()</span> function, you can use indices to extract or to change a specific row or column name. You can correct the mistake in the column names like this:\r\n<pre class=\"code\">&gt; colnames(baskets.team)[3] &lt;- “3rd”</pre>\r\nIf you want to get rid of either column names or row names, the only thing you need to do is set their value to <span class=\"code\">NULL</span>. This also works for vector names, by the way. You can try that out yourself on a copy of the matrix <span class=\"code\">baskets.team</span> like this:\r\n<pre class=\"code\">&gt; baskets.copy &lt;- baskets.team\r\n&gt; colnames(baskets.copy) &lt;- NULL\r\n&gt; baskets.copy\r\n [,1] [,2] [,3] [,4] [,5] [,6]\r\nGranny 12 4 5 6 9 3\r\nGeraldine 5 4 2 4 12 9</pre>\r\n<p class=\"TechnicalStuff\">R stores the row and column names in an attribute called <span class=\"code\">dimnames</span>. Use the <span class=\"code\">dimnames()</span> function to extract or set those values.</p>\r\n\r\n<h2 id=\"tab2\" >Using names as indices</h2>\r\nThese row and column names can be used just like you use names for values in a vector. You can use these names instead of the index number to select values from a vector. This works for matrices as well, using the row and column names.\r\n\r\nSay you want to select the second and the fifth game for both ladies; try:\r\n<pre class=\"code\">&gt; baskets.team[, c(“2nd”, “5th”)]\r\n 2nd 5th\r\nGranny 4 9\r\nGeraldine 4 12</pre>\r\nExactly as before, you get all rows if you don’t specify which ones you want. Alternatively, you can extract all the results for Granny like this:\r\n<pre class=\"code\">&gt; baskets.team[“Granny”, ]\r\n1st 2nd 3rd 4th 5th 6th\r\n 12 4 5 6 9 3</pre>\r\nThat’s the result, indeed, but the row name is gone now. R tries to simplify the matrix to a vector, if that’s possible. In this case, a single row is returned so, by default, this result is transformed to a vector.\r\n<p class=\"Remember\">If a one-row matrix is simplified to a vector, the column names are used as names for the values. If a one-column matrix is simplified to a vector, the row names are used as names for the vector. If you want to keep all names, you must set the argument <span class=\"code\">drop</span> to <span class=\"code\">FALSE</span> to avoid conversion to a vector.</p>","description":"The <span class=\"code\">rbind()</span> function in the <a href=\"https://www.dummies.com/programming/r/the-benefits-of-using-r/\" target=\"_blank\" rel=\"noopener\">R programming language</a> conveniently adds the names of the vectors to the rows of the matrix. You name the values in a vector, and you can do something very similar with rows and columns in a matrix.\r\n\r\nFor that, you have the functions <span class=\"code\">rownames()</span> and <span class=\"code\">colnames()</span>. Guess which one does what? Both functions work much like the <span class=\"code\">names()</span> function you use when naming vector values.\r\n<h2 id=\"tab1\" >Changing the row and column names</h2>\r\nThe matrix <span class=\"code\">baskets.team</span> already has some row names. It would be better if the names of the rows would just read <span class=\"code\">“</span><span class=\"code\">Granny</span><span class=\"code\">”</span> and <span class=\"code\">“</span><span class=\"code\">Geraldine</span><span class=\"code\">”</span>. You can easily change these row names like this:\r\n<pre class=\"code\">&gt; rownames(baskets.team) &lt;- c(“Granny”, “Geraldine”)</pre>\r\nYou can look at the matrix to check if this did what it’s supposed to do, or you can take a look at the row names itself like this:\r\n<pre class=\"code\">&gt; rownames(baskets.team)\r\n[1] “Granny” “Geraldine”</pre>\r\nThe <span class=\"code\">colnames()</span> function works exactly the same. You can, for example, add the number of the game as a column name using the following code:\r\n<pre class=\"code\">&gt; colnames(baskets.team) &lt;- c(“1st”, “2nd”, “3th”, “4th”, “5th”, “6th”)</pre>\r\nThis gives you the following matrix:\r\n<pre class=\"code\">&gt; baskets.team\r\n 1st 2nd 3th 4th 5th 6th\r\nGranny 12 4 5 6 9 3\r\nGeraldine 5 4 2 4 12 9</pre>\r\nThis is almost like you want it, but the third column name contains an annoying writing mistake. No problem there; R allows you to easily correct that mistake. Just as the with <span class=\"code\">names()</span> function, you can use indices to extract or to change a specific row or column name. You can correct the mistake in the column names like this:\r\n<pre class=\"code\">&gt; colnames(baskets.team)[3] &lt;- “3rd”</pre>\r\nIf you want to get rid of either column names or row names, the only thing you need to do is set their value to <span class=\"code\">NULL</span>. This also works for vector names, by the way. You can try that out yourself on a copy of the matrix <span class=\"code\">baskets.team</span> like this:\r\n<pre class=\"code\">&gt; baskets.copy &lt;- baskets.team\r\n&gt; colnames(baskets.copy) &lt;- NULL\r\n&gt; baskets.copy\r\n [,1] [,2] [,3] [,4] [,5] [,6]\r\nGranny 12 4 5 6 9 3\r\nGeraldine 5 4 2 4 12 9</pre>\r\n<p class=\"TechnicalStuff\">R stores the row and column names in an attribute called <span class=\"code\">dimnames</span>. Use the <span class=\"code\">dimnames()</span> function to extract or set those values.</p>\r\n\r\n<h2 id=\"tab2\" >Using names as indices</h2>\r\nThese row and column names can be used just like you use names for values in a vector. You can use these names instead of the index number to select values from a vector. This works for matrices as well, using the row and column names.\r\n\r\nSay you want to select the second and the fifth game for both ladies; try:\r\n<pre class=\"code\">&gt; baskets.team[, c(“2nd”, “5th”)]\r\n 2nd 5th\r\nGranny 4 9\r\nGeraldine 4 12</pre>\r\nExactly as before, you get all rows if you don’t specify which ones you want. Alternatively, you can extract all the results for Granny like this:\r\n<pre class=\"code\">&gt; baskets.team[“Granny”, ]\r\n1st 2nd 3rd 4th 5th 6th\r\n 12 4 5 6 9 3</pre>\r\nThat’s the result, indeed, but the row name is gone now. R tries to simplify the matrix to a vector, if that’s possible. In this case, a single row is returned so, by default, this result is transformed to a vector.\r\n<p class=\"Remember\">If a one-row matrix is simplified to a vector, the column names are used as names for the values. If a one-column matrix is simplified to a vector, the row names are used as names for the vector. If you want to keep all names, you must set the argument <span class=\"code\">drop</span> to <span class=\"code\">FALSE</span> to avoid conversion to a vector.</p>","blurb":"","authors":[{"authorId":9088,"name":"Andrie de Vries","slug":"andrie-de-vries","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9088"}},{"authorId":9089,"name":"Joris Meys","slug":"joris-meys","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9089"}}],"primaryCategoryTaxonomy":{"categoryId":33607,"title":"R","slug":"r","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"Changing the row and column names","target":"#tab1"},{"label":"Using names as indices","target":"#tab2"}],"relatedArticles":{"fromBook":[{"articleId":207492,"title":"R For Dummies Cheat Sheet","slug":"r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/207492"}},{"articleId":175059,"title":"How to Create a Data Frame from Scratch in R","slug":"how-to-create-a-data-frame-from-scratch-in-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/175059"}},{"articleId":142864,"title":"Importing Data into R","slug":"importing-data-into-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142864"}},{"articleId":142860,"title":"10 Online Resources for R Programming","slug":"10-online-resources-for-r-programming","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142860"}},{"articleId":142857,"title":"Subsetting R Objects","slug":"subsetting-r-objects","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142857"}}],"fromCategory":[{"articleId":262959,"title":"Statistical Analysis with R For Dummies Cheat Sheet","slug":"statistical-analysis-with-r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262959"}},{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281846,"slug":"r-for-dummies-2nd-edition","isbn":"9781119055808","categoryList":["technology","programming-web-design","r"],"amazon":{"default":"https://www.amazon.com/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119055806-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/r-for-dummies-2nd-edition-cover-9781119055808-203x255.jpg","width":203,"height":255},"title":"R For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9088\">Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b data-author-id=\"9089\">Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio-Engineering at the University of Ghent. </p>","authors":[{"authorId":9088,"name":"Andrie de Vries","slug":"andrie-de-vries","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9088"}},{"authorId":9089,"name":"Joris Meys","slug":"joris-meys","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9089"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119055808&quot;]}]\" id=\"du-slot-63221b04e77cb\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119055808&quot;]}]\" id=\"du-slot-63221b04e821f\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2021-09-13T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":141615},{"headers":{"creationTime":"2016-03-26T17:31:44+00:00","modifiedTime":"2021-10-28T20:48:43+00:00","timestamp":"2022-09-14T18:18:43+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"R","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"},"slug":"r","categoryId":33607}],"title":"How to Create a Data Frame from Scratch in R","strippedTitle":"how to create a data frame from scratch in r","slug":"how-to-create-a-data-frame-from-scratch-in-r","canonicalUrl":"","seo":{"metaDescription":"In the R programming language, there is a way to construct a data frame from scratch and add observations. Here's how to do it.","noIndex":0,"noFollow":0},"content":"In the <a href=\"https://www.dummies.com/programming/r/the-benefits-of-using-r/\" target=\"_blank\" rel=\"noopener\">R programming language</a>, a conversion from a matrix to a data frame can’t be used to construct a data frame with different types of values. If you combine both numeric and character data in a matrix, for example, everything will be converted to character.\r\n\r\nYou can construct a data frame from scratch, though, using the <span class=\"code\">data.frame()</span> function. Once a data frame is created, you can add <a href=\"https://www.dummies.com/programming/r/how-to-add-observations-to-a-data-frame-in-r\" target=\"_blank\" rel=\"noopener\">observations</a> to a data frame.\r\n<h2 id=\"tab1\" >Make a data frame from vectors in R</h2>\r\nSo, let’s make a little data frame with the names, salaries, and starting dates of a few imaginary co-workers. First, you create three vectors that contain the necessary information like this:\r\n<pre class=\"code\">&gt; employee &lt;- c('John Doe','Peter Gynn','Jolie Hope')\r\n&gt; salary &lt;- c(21000, 23400, 26800)\r\n&gt; startdate &lt;- as.Date(c('2010-11-1','2008-3-25','2007-3-14'))</pre>\r\nNow you have three different vectors in your workspace:\r\n<ul class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\">A <b>character vector</b> called <span class=\"code\">employee</span>, containing the names</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">A <b>numeric vector </b>called <span class=\"code\">salary</span>, containing the yearly salaries</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">A <b>date vector</b> called <span class=\"code\">startdate</span>, containing the dates on which the co-workers started</p>\r\n</li>\r\n</ul>\r\nNext, you combine the three vectors into a data frame using the following code:\r\n<pre class=\"code\">&gt; employ.data &lt;- data.frame(employee, salary, startdate)</pre>\r\nThe result of this is a data frame, <span class=\"code\">employ.data</span>, with the following structure:\r\n<pre class=\"code\">&gt; str(employ.data)\r\n'data.frame': 3 obs. of 3 variables:\r\n $ employee : Factor w/ 3 levels \"John Doe\",\"Jolie Hope\",..: 1 3 2\r\n $ salary : num 21000 23400 26800\r\n $ startdate: Date, format: \"2010-11-01\" \"2008-03-25\" ...</pre>\r\n<p class=\"Tip\">To combine a number of vectors into a data frame, you simply add all vectors as arguments to the <span class=\"code\">data.frame()</span> function, separated by commas. R will create a data frame with the variables that are named the same as the vectors used.</p>\r\n\r\n<h2 id=\"tab2\" >Keep characters as characters in R</h2>\r\nYou may have noticed something odd when looking at the structure of <span class=\"code\">employ.data</span>. Whereas the vector <span class=\"code\">employee</span> is a character vector, R made the variable <span class=\"code\">employee</span> in the data frame a factor.\r\n\r\nR does this by default, but you have an extra argument to the <span class=\"code\">data.frame()</span> function that can avoid this — namely, the argument <span class=\"code\">stringsAsFactors</span>. In the <span class=\"code\">employ.data</span> example, you can prevent the transformation to a factor of the <span class=\"code\">employee</span> variable by using the following code:\r\n<pre class=\"code\">&gt; employ.data &lt;- data.frame(employee, salary, startdate, stringsAsFactors=FALSE)</pre>\r\nIf you look at the structure of the data frame now, you see that the variable <span class=\"code\">employee</span> is a character vector, as shown in the following output:\r\n<pre class=\"code\">&gt; str(employ.data)\r\n'data.frame': 3 obs. of 3 variables:\r\n $ employee : chr \"John Doe\" \"Peter Gynn\" \"Jolie Hope\"\r\n $ salary : num 21000 23400 26800\r\n $ startdate: Date, format: \"2010-11-01\" \"2008-03-25\" ...</pre>\r\n<p class=\"Warning\">By default, R always transforms character vectors to factors when creating a data frame with character vectors or converting a character matrix to a data frame. This can be a nasty cause of errors in your code if you’re not aware of it. If you make it a habit to always specify the <span class=\"code\">stringsAsFactors</span> argument, you can avoid a lot of frustration.</p>","description":"In the <a href=\"https://www.dummies.com/programming/r/the-benefits-of-using-r/\" target=\"_blank\" rel=\"noopener\">R programming language</a>, a conversion from a matrix to a data frame can’t be used to construct a data frame with different types of values. If you combine both numeric and character data in a matrix, for example, everything will be converted to character.\r\n\r\nYou can construct a data frame from scratch, though, using the <span class=\"code\">data.frame()</span> function. Once a data frame is created, you can add <a href=\"https://www.dummies.com/programming/r/how-to-add-observations-to-a-data-frame-in-r\" target=\"_blank\" rel=\"noopener\">observations</a> to a data frame.\r\n<h2 id=\"tab1\" >Make a data frame from vectors in R</h2>\r\nSo, let’s make a little data frame with the names, salaries, and starting dates of a few imaginary co-workers. First, you create three vectors that contain the necessary information like this:\r\n<pre class=\"code\">&gt; employee &lt;- c('John Doe','Peter Gynn','Jolie Hope')\r\n&gt; salary &lt;- c(21000, 23400, 26800)\r\n&gt; startdate &lt;- as.Date(c('2010-11-1','2008-3-25','2007-3-14'))</pre>\r\nNow you have three different vectors in your workspace:\r\n<ul class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\">A <b>character vector</b> called <span class=\"code\">employee</span>, containing the names</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">A <b>numeric vector </b>called <span class=\"code\">salary</span>, containing the yearly salaries</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">A <b>date vector</b> called <span class=\"code\">startdate</span>, containing the dates on which the co-workers started</p>\r\n</li>\r\n</ul>\r\nNext, you combine the three vectors into a data frame using the following code:\r\n<pre class=\"code\">&gt; employ.data &lt;- data.frame(employee, salary, startdate)</pre>\r\nThe result of this is a data frame, <span class=\"code\">employ.data</span>, with the following structure:\r\n<pre class=\"code\">&gt; str(employ.data)\r\n'data.frame': 3 obs. of 3 variables:\r\n $ employee : Factor w/ 3 levels \"John Doe\",\"Jolie Hope\",..: 1 3 2\r\n $ salary : num 21000 23400 26800\r\n $ startdate: Date, format: \"2010-11-01\" \"2008-03-25\" ...</pre>\r\n<p class=\"Tip\">To combine a number of vectors into a data frame, you simply add all vectors as arguments to the <span class=\"code\">data.frame()</span> function, separated by commas. R will create a data frame with the variables that are named the same as the vectors used.</p>\r\n\r\n<h2 id=\"tab2\" >Keep characters as characters in R</h2>\r\nYou may have noticed something odd when looking at the structure of <span class=\"code\">employ.data</span>. Whereas the vector <span class=\"code\">employee</span> is a character vector, R made the variable <span class=\"code\">employee</span> in the data frame a factor.\r\n\r\nR does this by default, but you have an extra argument to the <span class=\"code\">data.frame()</span> function that can avoid this — namely, the argument <span class=\"code\">stringsAsFactors</span>. In the <span class=\"code\">employ.data</span> example, you can prevent the transformation to a factor of the <span class=\"code\">employee</span> variable by using the following code:\r\n<pre class=\"code\">&gt; employ.data &lt;- data.frame(employee, salary, startdate, stringsAsFactors=FALSE)</pre>\r\nIf you look at the structure of the data frame now, you see that the variable <span class=\"code\">employee</span> is a character vector, as shown in the following output:\r\n<pre class=\"code\">&gt; str(employ.data)\r\n'data.frame': 3 obs. of 3 variables:\r\n $ employee : chr \"John Doe\" \"Peter Gynn\" \"Jolie Hope\"\r\n $ salary : num 21000 23400 26800\r\n $ startdate: Date, format: \"2010-11-01\" \"2008-03-25\" ...</pre>\r\n<p class=\"Warning\">By default, R always transforms character vectors to factors when creating a data frame with character vectors or converting a character matrix to a data frame. This can be a nasty cause of errors in your code if you’re not aware of it. If you make it a habit to always specify the <span class=\"code\">stringsAsFactors</span> argument, you can avoid a lot of frustration.</p>","blurb":"","authors":[{"authorId":9088,"name":"Andrie de Vries","slug":"andrie-de-vries","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9088"}},{"authorId":9089,"name":"Joris Meys","slug":"joris-meys","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9089"}}],"primaryCategoryTaxonomy":{"categoryId":33607,"title":"R","slug":"r","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"Make a data frame from vectors in R","target":"#tab1"},{"label":"Keep characters as characters in R","target":"#tab2"}],"relatedArticles":{"fromBook":[{"articleId":207492,"title":"R For Dummies Cheat Sheet","slug":"r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/207492"}},{"articleId":142864,"title":"Importing Data into R","slug":"importing-data-into-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142864"}},{"articleId":142860,"title":"10 Online Resources for R Programming","slug":"10-online-resources-for-r-programming","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142860"}},{"articleId":142857,"title":"Subsetting R Objects","slug":"subsetting-r-objects","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142857"}},{"articleId":142856,"title":"Getting Help with R","slug":"getting-help-with-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/142856"}}],"fromCategory":[{"articleId":262959,"title":"Statistical Analysis with R For Dummies Cheat Sheet","slug":"statistical-analysis-with-r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262959"}},{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281846,"slug":"r-for-dummies-2nd-edition","isbn":"9781119055808","categoryList":["technology","programming-web-design","r"],"amazon":{"default":"https://www.amazon.com/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119055806-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119055806/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/r-for-dummies-2nd-edition-cover-9781119055808-203x255.jpg","width":203,"height":255},"title":"R For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9088\">Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b data-author-id=\"9089\">Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio-Engineering at the University of Ghent. </p>","authors":[{"authorId":9088,"name":"Andrie de Vries","slug":"andrie-de-vries","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9088"}},{"authorId":9089,"name":"Joris Meys","slug":"joris-meys","description":" <p><b>Andrie de Vries</b> is a leading R expert and Business Services Director for Revolution Analytics. With over 20 years of experience, he provides consulting and training services in the use of R. <b>Joris Meys</b> is a statistician, R programmer and R lecturer with the faculty of Bio&#45;Engineering at the University of Ghent. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9089"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119055808&quot;]}]\" id=\"du-slot-63221b03dcdae\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119055808&quot;]}]\" id=\"du-slot-63221b03dd8d9\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Solve","lifeExpectancy":"Six months","lifeExpectancySetFrom":"2021-04-23T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":175059},{"headers":{"creationTime":"2017-07-04T03:24:41+00:00","modifiedTime":"2019-09-30T00:52:54+00:00","timestamp":"2022-09-14T18:17:19+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"R","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"},"slug":"r","categoryId":33607}],"title":"Standard Deviation in R","strippedTitle":"standard deviation in r","slug":"standard-deviation-r","canonicalUrl":"","seo":{"metaDescription":"After you calculate the variance of a set of numbers, you have a value whose units are different from your original measurements. For example, if your original ","noIndex":0,"noFollow":0},"content":"After you calculate the variance of a set of numbers, you have a value whose units are different from your original measurements. For example, if your original measurements are in inches, their variance is in <em>square</em> inches. This is because you square the deviations before you average them. So the variance in the five-score population in the preceding example is 6.8 square inches.\r\n\r\nIt might be hard to grasp what that means. Often, it's more intuitive if the variation statistic is in the same units as the original measurements. It's easy to turn variance into that kind of statistic. All you have to do is take the square root of the variance.\r\n\r\nLike the variance, this square root is so important that it is has a special name: standard deviation.\r\n<h2 id=\"tab1\" >Population standard deviation</h2>\r\nThe <em>standard deviation</em> of a population is the square root of the population variance. The symbol for the population standard deviation is Σ (sigma). Its formula is\r\n\r\n<a href=\"https://www.dummies.com/wp-content/uploads/eq05006.jpg\"><img class=\"alignnone size-full wp-image-241728\" src=\"https://www.dummies.com/wp-content/uploads/eq05006.jpg\" alt=\"eq05006\" width=\"400\" height=\"117\" /></a>\r\n\r\nFor this 5-score population of measurements (in inches):\r\n\r\n50, 47, 52, 46, and 45\r\n\r\nthe population variance is 6.8 square inches, and the population standard deviation is 2.61 inches (rounded off).\r\n<h2 id=\"tab2\" >Sample standard deviation</h2>\r\nThe standard deviation of a sample — an estimate of the standard deviation of a population — is the square root of the sample variance. Its symbol is <em>s</em> and its formula is\r\n\r\n<a href=\"https://www.dummies.com/wp-content/uploads/eq05007.jpg\"><img class=\"alignnone size-full wp-image-241729\" src=\"https://www.dummies.com/wp-content/uploads/eq05007.jpg\" alt=\"eq05007\" width=\"383\" height=\"117\" /></a>\r\n\r\nFor this sample of measurements (in inches):\r\n\r\n50, 47, 52, 46, and 45\r\n\r\nthe estimated population variance is 8.4 square inches, and the estimated population standard deviation is 2.92 inches (rounded off).\r\n<h2 id=\"tab3\" >Using R to compute standard deviation</h2>\r\nAs is the case with variance, using R to <a href=\"https://www.dummies.com/education/math/statistics/how-to-calculate-standard-deviation-in-a-statistical-data-set/\">compute the standard deviation</a> is easy: You use the <code>sd() </code>function. And like its variance counterpart, <code>sd() </code>calculates <em>s</em>, not Σ:\r\n\r\n<code>&gt; sd(heights)\r\n</code>\r\n<code>[1] 2.915476</code>\r\n\r\n \r\n\r\nFor Σ — treating the five numbers as a self-contained population, in other words — you have to multiply the <code>sd() </code>result by the square root of (<em>N</em>-1)/<em>N</em>:\r\n\r\n<code>&gt; sd(heights)*(sqrt((length(heights)-1)/length(heights)))\r\n</code>\r\n<code>[1] 2.607681</code>\r\n\r\nAgain, if you're going to use this one frequently, defining a function is a good idea:\r\n\r\n<code>sd.p=function(x){sd(x)*sqrt((length(x)-1)/length(x))}\r\n</code>\r\nAnd here's how you use this function:\r\n\r\n<code>&gt; sd.p(heights)</code>\r\n\r\n<code>[1] 2.607681</code>","description":"After you calculate the variance of a set of numbers, you have a value whose units are different from your original measurements. For example, if your original measurements are in inches, their variance is in <em>square</em> inches. This is because you square the deviations before you average them. So the variance in the five-score population in the preceding example is 6.8 square inches.\r\n\r\nIt might be hard to grasp what that means. Often, it's more intuitive if the variation statistic is in the same units as the original measurements. It's easy to turn variance into that kind of statistic. All you have to do is take the square root of the variance.\r\n\r\nLike the variance, this square root is so important that it is has a special name: standard deviation.\r\n<h2 id=\"tab1\" >Population standard deviation</h2>\r\nThe <em>standard deviation</em> of a population is the square root of the population variance. The symbol for the population standard deviation is Σ (sigma). Its formula is\r\n\r\n<a href=\"https://www.dummies.com/wp-content/uploads/eq05006.jpg\"><img class=\"alignnone size-full wp-image-241728\" src=\"https://www.dummies.com/wp-content/uploads/eq05006.jpg\" alt=\"eq05006\" width=\"400\" height=\"117\" /></a>\r\n\r\nFor this 5-score population of measurements (in inches):\r\n\r\n50, 47, 52, 46, and 45\r\n\r\nthe population variance is 6.8 square inches, and the population standard deviation is 2.61 inches (rounded off).\r\n<h2 id=\"tab2\" >Sample standard deviation</h2>\r\nThe standard deviation of a sample — an estimate of the standard deviation of a population — is the square root of the sample variance. Its symbol is <em>s</em> and its formula is\r\n\r\n<a href=\"https://www.dummies.com/wp-content/uploads/eq05007.jpg\"><img class=\"alignnone size-full wp-image-241729\" src=\"https://www.dummies.com/wp-content/uploads/eq05007.jpg\" alt=\"eq05007\" width=\"383\" height=\"117\" /></a>\r\n\r\nFor this sample of measurements (in inches):\r\n\r\n50, 47, 52, 46, and 45\r\n\r\nthe estimated population variance is 8.4 square inches, and the estimated population standard deviation is 2.92 inches (rounded off).\r\n<h2 id=\"tab3\" >Using R to compute standard deviation</h2>\r\nAs is the case with variance, using R to <a href=\"https://www.dummies.com/education/math/statistics/how-to-calculate-standard-deviation-in-a-statistical-data-set/\">compute the standard deviation</a> is easy: You use the <code>sd() </code>function. And like its variance counterpart, <code>sd() </code>calculates <em>s</em>, not Σ:\r\n\r\n<code>&gt; sd(heights)\r\n</code>\r\n<code>[1] 2.915476</code>\r\n\r\n \r\n\r\nFor Σ — treating the five numbers as a self-contained population, in other words — you have to multiply the <code>sd() </code>result by the square root of (<em>N</em>-1)/<em>N</em>:\r\n\r\n<code>&gt; sd(heights)*(sqrt((length(heights)-1)/length(heights)))\r\n</code>\r\n<code>[1] 2.607681</code>\r\n\r\nAgain, if you're going to use this one frequently, defining a function is a good idea:\r\n\r\n<code>sd.p=function(x){sd(x)*sqrt((length(x)-1)/length(x))}\r\n</code>\r\nAnd here's how you use this function:\r\n\r\n<code>&gt; sd.p(heights)</code>\r\n\r\n<code>[1] 2.607681</code>","blurb":"","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"primaryCategoryTaxonomy":{"categoryId":33607,"title":"R","slug":"r","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"Population standard deviation","target":"#tab1"},{"label":"Sample standard deviation","target":"#tab2"},{"label":"Using R to compute standard deviation","target":"#tab3"}],"relatedArticles":{"fromBook":[{"articleId":262959,"title":"Statistical Analysis with R For Dummies Cheat Sheet","slug":"statistical-analysis-with-r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262959"}},{"articleId":241780,"title":"Testing a Variance in R","slug":"testing-variance-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241780"}},{"articleId":241777,"title":"Plotting t in ggplot2","slug":"plotting-t-ggplot2","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241777"}},{"articleId":241774,"title":"Plotting t in Base R Graphics","slug":"plotting-t-base-r-graphics","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241774"}},{"articleId":241770,"title":"Z Testing in R","slug":"z-testing-r","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241770"}}],"fromCategory":[{"articleId":262959,"title":"Statistical Analysis with R For Dummies Cheat Sheet","slug":"statistical-analysis-with-r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262959"}},{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281874,"slug":"statistical-analysis-with-r-for-dummies","isbn":"9781119337065","categoryList":["technology","programming-web-design","r"],"amazon":{"default":"https://www.amazon.com/gp/product/1119337062/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119337062/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119337062-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119337062/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119337062/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/statistical-analysis-with-r-for-dummies-cover-9781119337065-203x255.jpg","width":203,"height":255},"title":"Statistical Analysis with R For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9759\">Joseph Schmuller, PhD,</b> has taught undergraduate and graduate statistics, and has 25 years of IT experience. The author of four editions of <i>Statistical Analysis with Excel For Dummies</i> and three editions of <i>Teach Yourself UML in 24 Hours</i> (SAMS), he has created online coursework for Lynda.com and is a former Editor in Chief of <i>PC AI</i> magazine. He is a Research Scholar at the University of North Florida. </p>","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119337065&quot;]}]\" id=\"du-slot-63221aafd0778\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119337065&quot;]}]\" id=\"du-slot-63221aafd1001\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":241727},{"headers":{"creationTime":"2018-04-11T18:08:15+00:00","modifiedTime":"2018-04-11T18:08:15+00:00","timestamp":"2022-09-14T18:16:24+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"R","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"},"slug":"r","categoryId":33607}],"title":"R Project: Combining an Image with an Animated Image","strippedTitle":"r project: combining an image with an animated image","slug":"r-project-combining-image-animated-image","canonicalUrl":"","seo":{"metaDescription":"If you’ve been working with images, animated images, and combined stationary images in R, it may be time to take the next step. This project walks you through t","noIndex":0,"noFollow":0},"content":"If you’ve been working with images, animated images, and combined stationary images in R, it may be time to take the next step. This project walks you through the next step: Combine an image with an animated image.\r\n\r\nThis image shows the end product — the plot of the <code>iris</code> data set with comedy icons Laurel and Hardy positioned in front of the plot legend. When you open this combined image in the Viewer, you see Stan and Ollie dancing their little derbies off. (The derbies don’t actually come off in the animation, but you get the drift.)\r\n\r\n[caption id=\"attachment_251667\" align=\"aligncenter\" width=\"535\"]<img class=\"wp-image-251667 size-full\" src=\"https://www.dummies.com/wp-content/uploads/r-projects-laurel-hardy.jpg\" alt=\"Laurel and Hardy iris plot\" width=\"535\" height=\"305\" /> Laurel and Hardy, dancing in front of the legend in the <code>iris</code> plot.[/caption]\r\n<h2 id=\"tab1\" ><a name=\"_Toc499615383\"></a><a name=\"_Toc499616061\"></a>Getting Stan and Ollie</h2>\r\nCheck out the <a href=\"http://www.animatedimages.org/img-animated-dancing-image-0243-79244.htm\">Laurel and Hardy GIF</a>. Right-click the image and select Save Image As from the pop-up menu that appears. Save it as <code>animated-dancing-image-0243</code> in your <code>Documents</code> folder.\r\n\r\nThen read it into R:\r\n\r\n<code>l_and_h &lt;- image_read(\"animated-dancing-image-0243.gif\")</code>\r\n\r\nApplying the <code>length()</code> function to <code>l_and_h</code>\r\n\r\n<code>&gt; length(l_and_h)</code>\r\n\r\n<code>[1] 10</code>\r\n\r\nindicates that this GIF consists of ten frames.\r\n<p class=\"article-tips tip\">To add a coolness factor, make the background of the GIF transparent before <code>image_read()</code> works with it. This <a href=\"http://www.online-image-editor.com/\">free online image editor</a> does the job quite nicely.</p>\r\n\r\n<h2 id=\"tab2\" ><a name=\"_Toc499615384\"></a><a name=\"_Toc499616062\"></a>Combining the boys with the background</h2>\r\nIf you use the image combination technique, the code looks like this:\r\n\r\n<code>image_composite(image=background, composite_image=l_and_h, offset = \"+510+200\")</code>\r\n\r\nThe picture it produces looks like the image above but with one problem: The boys aren’t dancing. Why is that?\r\n\r\nThe reason is that <code>image_composite()</code> combined the <code>background</code> with just the first frame of <code>l_and_h</code>, not with all ten. It’s exactly the same as if you had run\r\n<pre class=\"code\">image_composite(image=background, composite_image=l_and_h[1], \r\n offset = \"+510+200\")</pre>\r\nThe <code>length()</code> function verifies this:\r\n<pre class=\"code\">&gt; length(image_composite(image=background, composite_image=l_and_h, \r\n offset = \"+510+200\"))\r\n[1] 1</pre>\r\nIf all ten frames were involved, the <code>length()</code> function would have returned 10.\r\n\r\nTo get this done properly, you have to use a <code>magick</code> function called <code>image_apply()</code>.\r\n<h2 id=\"tab3\" ><a name=\"_Toc499615385\"></a><a name=\"_Toc499616063\"></a>Explaining image_apply()</h2>\r\nSo that you fully understand how this important function works, let's describe an analogous function called <code>lapply()</code>.\r\n\r\nIf you want to apply a function (like <code>mean()</code>) to the variables of a data frame, like <code>iris</code>, one way to do that is with a <code>for</code> loop: Start with the first column and calculate its mean, go to the next column and calculate its mean, and so on until you calculate all the column means.\r\n\r\nFor technical reasons, it’s faster and more efficient to use <code>lapply()</code> to apply <code>mean()</code> to all the variables:\r\n<pre class=\"code\">&gt; lapply(iris, mean)\r\n$Sepal.Length\r\n[1] 5.843333\r\n\r\n$Sepal.Width\r\n[1] 3.057333\r\n\r\n$Petal.Length\r\n[1] 3.758\r\n\r\n$Petal.Width\r\n[1] 1.199333\r\n\r\n$Species\r\n[1] NA</pre>\r\nA warning message comes with that last one, but that’s okay.\r\n\r\nAnother way to write <code>lapply(iris, mean)</code> is <code>lapply(iris, function(x){mean(x)})</code>.\r\n\r\nThis second way comes in handy when the function becomes more complicated. If, for some reason, you want to square the value of each score in the data set and then multiply the result by three, and then calculate the mean of each column, here’s how to code it:\r\n\r\n<code>lapply(iris, function(x){mean(3*(x^2))})</code>\r\n\r\nIn a similar way, <code>image_apply()</code> applies a function to every frame in an animated GIF. In this project, the function that gets applied to every frame is <code>image_composite()</code>:\r\n\r\n<code>function(frame){image_composite(image=background, composite_image=frame, offset = \"+510+200\")}</code>\r\n\r\nSo, within <code>image_apply()</code>, that’s\r\n<pre class=\"code\">frames &lt;- image_apply(image=l_and_h, function(frame) {\r\n image_composite(image=background, composite_image=frame, offset = \"+510+200\")\r\n})</pre>\r\nAfter you run that code, <code>length(frames)</code> verifies the ten frames:\r\n\r\n<code>&gt; length(frames)</code>\r\n<code>[1] 10</code>\r\n<h2 id=\"tab4\" ><a name=\"_Toc499615386\"></a><a name=\"_Toc499616064\"></a>Getting back to the animation</h2>\r\nThe <code>image_animate()</code> function puts it all in motion at ten frames per second:\r\n\r\n<code>animation &lt;- image_animate(frames, fps = 10)</code>\r\n\r\nTo put the show on the screen, it’s\r\n\r\n<code>print(animation)</code>\r\n\r\nAll together now:\r\n<pre class=\"code\">l_and_h &lt;- image_read(\"animated-dancing-image-0243.gif\")\r\nbackground &lt;- image_background(iris_plot, \"white)\r\n\r\nframes &lt;- image_apply(image=l_and_h, function(frame) {\r\n image_composite(image=background, composite_image=frame, offset = \"+510+200\")\r\n})\r\n\r\nanimation &lt;- image_animate(frames, fps = 10)\r\nprint(animation)</pre>\r\nAnd that’s the code for the image above.\r\n\r\nOne more thing. The <code>image_write()</code> function saves the animation as a handy little reusable GIF:\r\n\r\n<code>image_write(animation, \"LHirises.gif\")</code>","description":"If you’ve been working with images, animated images, and combined stationary images in R, it may be time to take the next step. This project walks you through the next step: Combine an image with an animated image.\r\n\r\nThis image shows the end product — the plot of the <code>iris</code> data set with comedy icons Laurel and Hardy positioned in front of the plot legend. When you open this combined image in the Viewer, you see Stan and Ollie dancing their little derbies off. (The derbies don’t actually come off in the animation, but you get the drift.)\r\n\r\n[caption id=\"attachment_251667\" align=\"aligncenter\" width=\"535\"]<img class=\"wp-image-251667 size-full\" src=\"https://www.dummies.com/wp-content/uploads/r-projects-laurel-hardy.jpg\" alt=\"Laurel and Hardy iris plot\" width=\"535\" height=\"305\" /> Laurel and Hardy, dancing in front of the legend in the <code>iris</code> plot.[/caption]\r\n<h2 id=\"tab1\" ><a name=\"_Toc499615383\"></a><a name=\"_Toc499616061\"></a>Getting Stan and Ollie</h2>\r\nCheck out the <a href=\"http://www.animatedimages.org/img-animated-dancing-image-0243-79244.htm\">Laurel and Hardy GIF</a>. Right-click the image and select Save Image As from the pop-up menu that appears. Save it as <code>animated-dancing-image-0243</code> in your <code>Documents</code> folder.\r\n\r\nThen read it into R:\r\n\r\n<code>l_and_h &lt;- image_read(\"animated-dancing-image-0243.gif\")</code>\r\n\r\nApplying the <code>length()</code> function to <code>l_and_h</code>\r\n\r\n<code>&gt; length(l_and_h)</code>\r\n\r\n<code>[1] 10</code>\r\n\r\nindicates that this GIF consists of ten frames.\r\n<p class=\"article-tips tip\">To add a coolness factor, make the background of the GIF transparent before <code>image_read()</code> works with it. This <a href=\"http://www.online-image-editor.com/\">free online image editor</a> does the job quite nicely.</p>\r\n\r\n<h2 id=\"tab2\" ><a name=\"_Toc499615384\"></a><a name=\"_Toc499616062\"></a>Combining the boys with the background</h2>\r\nIf you use the image combination technique, the code looks like this:\r\n\r\n<code>image_composite(image=background, composite_image=l_and_h, offset = \"+510+200\")</code>\r\n\r\nThe picture it produces looks like the image above but with one problem: The boys aren’t dancing. Why is that?\r\n\r\nThe reason is that <code>image_composite()</code> combined the <code>background</code> with just the first frame of <code>l_and_h</code>, not with all ten. It’s exactly the same as if you had run\r\n<pre class=\"code\">image_composite(image=background, composite_image=l_and_h[1], \r\n offset = \"+510+200\")</pre>\r\nThe <code>length()</code> function verifies this:\r\n<pre class=\"code\">&gt; length(image_composite(image=background, composite_image=l_and_h, \r\n offset = \"+510+200\"))\r\n[1] 1</pre>\r\nIf all ten frames were involved, the <code>length()</code> function would have returned 10.\r\n\r\nTo get this done properly, you have to use a <code>magick</code> function called <code>image_apply()</code>.\r\n<h2 id=\"tab3\" ><a name=\"_Toc499615385\"></a><a name=\"_Toc499616063\"></a>Explaining image_apply()</h2>\r\nSo that you fully understand how this important function works, let's describe an analogous function called <code>lapply()</code>.\r\n\r\nIf you want to apply a function (like <code>mean()</code>) to the variables of a data frame, like <code>iris</code>, one way to do that is with a <code>for</code> loop: Start with the first column and calculate its mean, go to the next column and calculate its mean, and so on until you calculate all the column means.\r\n\r\nFor technical reasons, it’s faster and more efficient to use <code>lapply()</code> to apply <code>mean()</code> to all the variables:\r\n<pre class=\"code\">&gt; lapply(iris, mean)\r\n$Sepal.Length\r\n[1] 5.843333\r\n\r\n$Sepal.Width\r\n[1] 3.057333\r\n\r\n$Petal.Length\r\n[1] 3.758\r\n\r\n$Petal.Width\r\n[1] 1.199333\r\n\r\n$Species\r\n[1] NA</pre>\r\nA warning message comes with that last one, but that’s okay.\r\n\r\nAnother way to write <code>lapply(iris, mean)</code> is <code>lapply(iris, function(x){mean(x)})</code>.\r\n\r\nThis second way comes in handy when the function becomes more complicated. If, for some reason, you want to square the value of each score in the data set and then multiply the result by three, and then calculate the mean of each column, here’s how to code it:\r\n\r\n<code>lapply(iris, function(x){mean(3*(x^2))})</code>\r\n\r\nIn a similar way, <code>image_apply()</code> applies a function to every frame in an animated GIF. In this project, the function that gets applied to every frame is <code>image_composite()</code>:\r\n\r\n<code>function(frame){image_composite(image=background, composite_image=frame, offset = \"+510+200\")}</code>\r\n\r\nSo, within <code>image_apply()</code>, that’s\r\n<pre class=\"code\">frames &lt;- image_apply(image=l_and_h, function(frame) {\r\n image_composite(image=background, composite_image=frame, offset = \"+510+200\")\r\n})</pre>\r\nAfter you run that code, <code>length(frames)</code> verifies the ten frames:\r\n\r\n<code>&gt; length(frames)</code>\r\n<code>[1] 10</code>\r\n<h2 id=\"tab4\" ><a name=\"_Toc499615386\"></a><a name=\"_Toc499616064\"></a>Getting back to the animation</h2>\r\nThe <code>image_animate()</code> function puts it all in motion at ten frames per second:\r\n\r\n<code>animation &lt;- image_animate(frames, fps = 10)</code>\r\n\r\nTo put the show on the screen, it’s\r\n\r\n<code>print(animation)</code>\r\n\r\nAll together now:\r\n<pre class=\"code\">l_and_h &lt;- image_read(\"animated-dancing-image-0243.gif\")\r\nbackground &lt;- image_background(iris_plot, \"white)\r\n\r\nframes &lt;- image_apply(image=l_and_h, function(frame) {\r\n image_composite(image=background, composite_image=frame, offset = \"+510+200\")\r\n})\r\n\r\nanimation &lt;- image_animate(frames, fps = 10)\r\nprint(animation)</pre>\r\nAnd that’s the code for the image above.\r\n\r\nOne more thing. The <code>image_write()</code> function saves the animation as a handy little reusable GIF:\r\n\r\n<code>image_write(animation, \"LHirises.gif\")</code>","blurb":"","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"primaryCategoryTaxonomy":{"categoryId":33607,"title":"R","slug":"r","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"Getting Stan and Ollie","target":"#tab1"},{"label":"Combining the boys with the background","target":"#tab2"},{"label":"Explaining image_apply()","target":"#tab3"},{"label":"Getting back to the animation","target":"#tab4"}],"relatedArticles":{"fromBook":[{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}},{"articleId":251653,"title":"R Project for Neural Networks: Rattling Around","slug":"r-project-neural-networks-rattling-around","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251653"}},{"articleId":251649,"title":"Artificial Neural Networks and R Programming","slug":"artificial-neural-networks-r-programming","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251649"}}],"fromCategory":[{"articleId":262959,"title":"Statistical Analysis with R For Dummies Cheat Sheet","slug":"statistical-analysis-with-r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262959"}},{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}},{"articleId":251653,"title":"R Project for Neural Networks: Rattling Around","slug":"r-project-neural-networks-rattling-around","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251653"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281847,"slug":"r-projects-for-dummies","isbn":"9781119446187","categoryList":["technology","programming-web-design","r"],"amazon":{"default":"https://www.amazon.com/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/111944618X-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/r-projects-for-dummies-cover-9781119446187-203x255.jpg","width":203,"height":255},"title":"R Projects For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9759\">Joseph Schmuller, PhD,</b> is a veteran of more than 25 years in Information Technology. He is the author of several books, including <i>Statistical Analysis with R For Dummies</i> and four editions of <i>Statistical Analysis with Excel For Dummies.</i> In addition, he has written numerous articles and created online coursework for Lynda.com. </p>","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119446187&quot;]}]\" id=\"du-slot-63221a787ffc9\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119446187&quot;]}]\" id=\"du-slot-63221a788083a\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":251666},{"headers":{"creationTime":"2018-04-11T15:18:09+00:00","modifiedTime":"2018-04-11T15:18:09+00:00","timestamp":"2022-09-14T18:16:24+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"R","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"},"slug":"r","categoryId":33607}],"title":"11 Useful Resources for R Programmers","strippedTitle":"11 useful resources for r programmers","slug":"11-useful-resources-r-programmers","canonicalUrl":"","seo":{"metaDescription":"Here, you learn about books and websites that help you learn more about R programming. Without further ado. . . Interacting with users If you want to delve deep","noIndex":0,"noFollow":0},"content":"Here, you learn about books and websites that help you learn more about R programming. Without further ado. . .\r\n<h2 id=\"tab1\" ><a name=\"_Toc499615390\"></a>Interacting with users</h2>\r\nIf you want to delve deeper into R applications that interact with users, start with <a href=\"https://shiny.rstudio.com/tutorial\">this tutorial by shiny guiding force Garrett Grolemund.</a>\r\n\r\nFor a helpful book on the subject, consider Chris Beeley’s <em>web Application Development with R Using Shiny,</em> 2nd Edition (Packt Publishing, 2016).\r\n<h2 id=\"tab2\" ><a name=\"_Toc499615391\"></a>Machine learning</h2>\r\nFor the lowdown on all things <code>Rattle</code>, go directly to the source: <code>Rattle</code> creator Graham Williams has written <em>Data Mining with Rattle and R: The Art of Excavating Data for Knowledge Discovery</em> (Springer, 2011). Check out the <a href=\"https://rattle.togaware.com/\">companion website</a>.\r\n\r\nThe University of California-Irvine Machine Learning Repository plays such a huge role in the R programming world. Here’s how its creator prefers that you look for the material:\r\n\r\nLichman, M. (2013). UCI Machine Learning Repository [<a href=\"http://archive.ics.uci.edu/ml\">http://archive.ics.uci.edu/ml</a>]. Irvine, CA: University of California, School of Information and Computer Science.\r\n\r\nThank you, UCI Anteaters!\r\n\r\nIf machine learning interests you, take a comprehensive look at the field (under its other name, “statistical learning”): Gareth James, Daniela Witten, Trevor Hastie, and Robert Tibshirani’s <em>An Introduction to Statistical Learning with Applications in R</em> (Springer, 2017).\r\n\r\n<em><a href=\"http://www.infor.uva.es/~teodoro/neuro-intro.pdf\">An Introduction to Neural Networks</a>,</em> by Ben Krose and Patrick van der Smagt, is a little dated, but you can get it for the low, low price of nothing:\r\n<p class=\"article-tips tip\">After you download a large PDF, it’s a good idea to upload it into an ebook app, like Google Play Books. That turns the PDF into an ebook and makes it easier to navigate on a tablet.</p>\r\n\r\n<h2 id=\"tab3\" ><a name=\"_Toc499615392\"></a>Databases</h2>\r\nThe R-bloggers website has a nice <a href=\"http://www.r-bloggers.com/working-with-databases-in-r\">article on working with databases</a>.\r\n\r\nOf course, R-bloggers has terrific articles on a lot of R-related topics!\r\n\r\nYou can learn quite a bit about RFM (Recency Frequency Money) analysis and customer segmentation at <a href=\"https://www.putler.com/rfm-analysis/\">www.putler.com/rfm-analysis</a>.\r\n<h2 id=\"tab4\" ><a name=\"_Toc499615393\"></a>Maps and images</h2>\r\nThe area of maps is a fascinating one. You might be interested in something at a higher level. If so, read <em><a href=\"https://cran.r-project.org/doc/contrib/intro-spatial-rl.pdf\">Introduction to visualising spatial data in R by Robin Lovelace, James Cheshire, Rachel Oldroyd (and others)</a></em>.\r\n\r\n<a href=\"https://journal.r-project.org/archive/2013-1/kahle-wickham.pdf\">David Kahle and Hadley Wickham’s <em>ggmap: Spatial Visualization with ggplot2</em></a> is also at a higher level.\r\n\r\nFascinated by <code>magick</code>? The best place to go is the <a href=\"https://cran.r-project.org/web/packages/magick/vignettes/intro.html%20-%20drawing_and_graphics\">primary source</a>. Check it out.","description":"Here, you learn about books and websites that help you learn more about R programming. Without further ado. . .\r\n<h2 id=\"tab1\" ><a name=\"_Toc499615390\"></a>Interacting with users</h2>\r\nIf you want to delve deeper into R applications that interact with users, start with <a href=\"https://shiny.rstudio.com/tutorial\">this tutorial by shiny guiding force Garrett Grolemund.</a>\r\n\r\nFor a helpful book on the subject, consider Chris Beeley’s <em>web Application Development with R Using Shiny,</em> 2nd Edition (Packt Publishing, 2016).\r\n<h2 id=\"tab2\" ><a name=\"_Toc499615391\"></a>Machine learning</h2>\r\nFor the lowdown on all things <code>Rattle</code>, go directly to the source: <code>Rattle</code> creator Graham Williams has written <em>Data Mining with Rattle and R: The Art of Excavating Data for Knowledge Discovery</em> (Springer, 2011). Check out the <a href=\"https://rattle.togaware.com/\">companion website</a>.\r\n\r\nThe University of California-Irvine Machine Learning Repository plays such a huge role in the R programming world. Here’s how its creator prefers that you look for the material:\r\n\r\nLichman, M. (2013). UCI Machine Learning Repository [<a href=\"http://archive.ics.uci.edu/ml\">http://archive.ics.uci.edu/ml</a>]. Irvine, CA: University of California, School of Information and Computer Science.\r\n\r\nThank you, UCI Anteaters!\r\n\r\nIf machine learning interests you, take a comprehensive look at the field (under its other name, “statistical learning”): Gareth James, Daniela Witten, Trevor Hastie, and Robert Tibshirani’s <em>An Introduction to Statistical Learning with Applications in R</em> (Springer, 2017).\r\n\r\n<em><a href=\"http://www.infor.uva.es/~teodoro/neuro-intro.pdf\">An Introduction to Neural Networks</a>,</em> by Ben Krose and Patrick van der Smagt, is a little dated, but you can get it for the low, low price of nothing:\r\n<p class=\"article-tips tip\">After you download a large PDF, it’s a good idea to upload it into an ebook app, like Google Play Books. That turns the PDF into an ebook and makes it easier to navigate on a tablet.</p>\r\n\r\n<h2 id=\"tab3\" ><a name=\"_Toc499615392\"></a>Databases</h2>\r\nThe R-bloggers website has a nice <a href=\"http://www.r-bloggers.com/working-with-databases-in-r\">article on working with databases</a>.\r\n\r\nOf course, R-bloggers has terrific articles on a lot of R-related topics!\r\n\r\nYou can learn quite a bit about RFM (Recency Frequency Money) analysis and customer segmentation at <a href=\"https://www.putler.com/rfm-analysis/\">www.putler.com/rfm-analysis</a>.\r\n<h2 id=\"tab4\" ><a name=\"_Toc499615393\"></a>Maps and images</h2>\r\nThe area of maps is a fascinating one. You might be interested in something at a higher level. If so, read <em><a href=\"https://cran.r-project.org/doc/contrib/intro-spatial-rl.pdf\">Introduction to visualising spatial data in R by Robin Lovelace, James Cheshire, Rachel Oldroyd (and others)</a></em>.\r\n\r\n<a href=\"https://journal.r-project.org/archive/2013-1/kahle-wickham.pdf\">David Kahle and Hadley Wickham’s <em>ggmap: Spatial Visualization with ggplot2</em></a> is also at a higher level.\r\n\r\nFascinated by <code>magick</code>? The best place to go is the <a href=\"https://cran.r-project.org/web/packages/magick/vignettes/intro.html%20-%20drawing_and_graphics\">primary source</a>. Check it out.","blurb":"","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"primaryCategoryTaxonomy":{"categoryId":33607,"title":"R","slug":"r","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"Interacting with users","target":"#tab1"},{"label":"Machine learning","target":"#tab2"},{"label":"Databases","target":"#tab3"},{"label":"Maps and images","target":"#tab4"}],"relatedArticles":{"fromBook":[{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}},{"articleId":251653,"title":"R Project for Neural Networks: Rattling Around","slug":"r-project-neural-networks-rattling-around","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251653"}},{"articleId":251649,"title":"Artificial Neural Networks and R Programming","slug":"artificial-neural-networks-r-programming","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251649"}}],"fromCategory":[{"articleId":262959,"title":"Statistical Analysis with R For Dummies Cheat Sheet","slug":"statistical-analysis-with-r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262959"}},{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251660,"title":"R Project: Delay and Weather","slug":"r-project-delay-weather","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251660"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}},{"articleId":251653,"title":"R Project for Neural Networks: Rattling Around","slug":"r-project-neural-networks-rattling-around","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251653"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281847,"slug":"r-projects-for-dummies","isbn":"9781119446187","categoryList":["technology","programming-web-design","r"],"amazon":{"default":"https://www.amazon.com/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/111944618X-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/r-projects-for-dummies-cover-9781119446187-203x255.jpg","width":203,"height":255},"title":"R Projects For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9759\">Joseph Schmuller, PhD,</b> is a veteran of more than 25 years in Information Technology. He is the author of several books, including <i>Statistical Analysis with R For Dummies</i> and four editions of <i>Statistical Analysis with Excel For Dummies.</i> In addition, he has written numerous articles and created online coursework for Lynda.com. </p>","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119446187&quot;]}]\" id=\"du-slot-63221a7878641\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119446187&quot;]}]\" id=\"du-slot-63221a7878eb3\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":251663},{"headers":{"creationTime":"2018-04-11T15:08:03+00:00","modifiedTime":"2018-04-11T15:08:03+00:00","timestamp":"2022-09-14T18:16:24+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"R","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"},"slug":"r","categoryId":33607}],"title":"R Project: Delay and Weather","strippedTitle":"r project: delay and weather","slug":"r-project-delay-weather","canonicalUrl":"","seo":{"metaDescription":"Try out this R project to see how one variable might affect an outcome. It’s conceivable that weather conditions could influence flight delays. How do you incor","noIndex":0,"noFollow":0},"content":"Try out this R project to see how one variable might affect an outcome. It’s conceivable that weather conditions could influence flight delays. How do you incorporate weather information into the assessment of delay?\r\n\r\nOne <code>nycflights13</code> data frame called weather provides the <code>weather</code> data for every day and hour at each of the three origin airports. Here’s a glimpse of exactly what it has:\r\n<pre class=\"code\">&gt; glimpse(weather,60)\r\nObservations: 26,130\r\nVariables: 15\r\n$ origin \"EWR\", \"EWR\", \"EWR\", \"EWR\", \"EWR\", \"...\r\n$ year 2013, 2013, 2013, 2013, 2013, 2013, ...\r\n$ month 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\r\n$ day 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\r\n$ hour 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 1...\r\n$ temp 37.04, 37.04, 37.94, 37.94, 37.94, 3...\r\n$ dewp 21.92, 21.92, 21.92, 23.00, 24.08, 2...\r\n$ humid 53.97, 53.97, 52.09, 54.51, 57.04, 5...\r\n$ wind_dir 230, 230, 230, 230, 240, 270, 250, 2...\r\n$ wind_speed 10.35702, 13.80936, 12.65858, 13.809...\r\n$ wind_gust 11.918651, 15.891535, 14.567241, 15....\r\n$ precip 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...\r\n$ pressure 1013.9, 1013.0, 1012.6, 1012.7, 1012...\r\n$ visib 10, 10, 10, 10, 10, 10, 10, 10, 10, ...\r\n$ time_hour 2012-12-31 19:00:00, 2012-12-31 20:...</pre>\r\nSo the variables it has in common with <code>flites_name_day</code> are the first six and the last one. To join the two data frames, use this code:\r\n<pre class=\"code\">flites_day_weather &lt;- flites_day %&gt;%\r\n inner_join(weather, by = c(\"origin\",\"year\",\"month\",\"day\",\"hour\",\"time_hour\"))</pre>\r\nNow you can use <code>flites_day_weather</code> to start answering questions about departure delay and the weather.\r\n\r\nWhat questions will you ask? How will you answer them? What plots will you draw? What regression lines will you create? Will <code>scale()</code> help?\r\n\r\nAnd, when you’re all done, take a look at arrival delay (<code>arr_delay</code>).","description":"Try out this R project to see how one variable might affect an outcome. It’s conceivable that weather conditions could influence flight delays. How do you incorporate weather information into the assessment of delay?\r\n\r\nOne <code>nycflights13</code> data frame called weather provides the <code>weather</code> data for every day and hour at each of the three origin airports. Here’s a glimpse of exactly what it has:\r\n<pre class=\"code\">&gt; glimpse(weather,60)\r\nObservations: 26,130\r\nVariables: 15\r\n$ origin \"EWR\", \"EWR\", \"EWR\", \"EWR\", \"EWR\", \"...\r\n$ year 2013, 2013, 2013, 2013, 2013, 2013, ...\r\n$ month 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\r\n$ day 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\r\n$ hour 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 1...\r\n$ temp 37.04, 37.04, 37.94, 37.94, 37.94, 3...\r\n$ dewp 21.92, 21.92, 21.92, 23.00, 24.08, 2...\r\n$ humid 53.97, 53.97, 52.09, 54.51, 57.04, 5...\r\n$ wind_dir 230, 230, 230, 230, 240, 270, 250, 2...\r\n$ wind_speed 10.35702, 13.80936, 12.65858, 13.809...\r\n$ wind_gust 11.918651, 15.891535, 14.567241, 15....\r\n$ precip 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...\r\n$ pressure 1013.9, 1013.0, 1012.6, 1012.7, 1012...\r\n$ visib 10, 10, 10, 10, 10, 10, 10, 10, 10, ...\r\n$ time_hour 2012-12-31 19:00:00, 2012-12-31 20:...</pre>\r\nSo the variables it has in common with <code>flites_name_day</code> are the first six and the last one. To join the two data frames, use this code:\r\n<pre class=\"code\">flites_day_weather &lt;- flites_day %&gt;%\r\n inner_join(weather, by = c(\"origin\",\"year\",\"month\",\"day\",\"hour\",\"time_hour\"))</pre>\r\nNow you can use <code>flites_day_weather</code> to start answering questions about departure delay and the weather.\r\n\r\nWhat questions will you ask? How will you answer them? What plots will you draw? What regression lines will you create? Will <code>scale()</code> help?\r\n\r\nAnd, when you’re all done, take a look at arrival delay (<code>arr_delay</code>).","blurb":"","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"primaryCategoryTaxonomy":{"categoryId":33607,"title":"R","slug":"r","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33607"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}},{"articleId":251653,"title":"R Project for Neural Networks: Rattling Around","slug":"r-project-neural-networks-rattling-around","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251653"}},{"articleId":251649,"title":"Artificial Neural Networks and R Programming","slug":"artificial-neural-networks-r-programming","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251649"}}],"fromCategory":[{"articleId":262959,"title":"Statistical Analysis with R For Dummies Cheat Sheet","slug":"statistical-analysis-with-r-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/262959"}},{"articleId":251666,"title":"R Project: Combining an Image with an Animated Image","slug":"r-project-combining-image-animated-image","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251666"}},{"articleId":251663,"title":"11 Useful Resources for R Programmers","slug":"11-useful-resources-r-programmers","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251663"}},{"articleId":251657,"title":"R Project for RFM Analysis: Another Data Set","slug":"r-project-rfm-analysis-another-data-set","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251657"}},{"articleId":251653,"title":"R Project for Neural Networks: Rattling Around","slug":"r-project-neural-networks-rattling-around","categoryList":["technology","programming-web-design","r"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/251653"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281847,"slug":"r-projects-for-dummies","isbn":"9781119446187","categoryList":["technology","programming-web-design","r"],"amazon":{"default":"https://www.amazon.com/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/111944618X-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/111944618X/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/r-projects-for-dummies-cover-9781119446187-203x255.jpg","width":203,"height":255},"title":"R Projects For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9759\">Joseph Schmuller, PhD,</b> is a veteran of more than 25 years in Information Technology. He is the author of several books, including <i>Statistical Analysis with R For Dummies</i> and four editions of <i>Statistical Analysis with Excel For Dummies.</i> In addition, he has written numerous articles and created online coursework for Lynda.com. </p>","authors":[{"authorId":9759,"name":"Joseph Schmuller","slug":"joseph-schmuller","description":" <p><b>Joseph Schmuller</b> works on the Digital & Enterprise Architecture Team at Availity. He has taught statistics at the undergraduate and graduate levels. He has created and delivered courses for LinkedIn Learning, and he is the author of all previous editions of <i>Statistical Analysis with Excel For Dummies.</i></p> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9759"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119446187&quot;]}]\" id=\"du-slot-63221a7870d6e\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;r&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119446187&quot;]}]\" id=\"du-slot-63221a7871601\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":251660}],"_links":{"self":{"self":"https://dummies-api.dummies.com/v2/categories/33607/categoryArticles?sortField=time&sortOrder=1&size=10&offset=0"},"next":{"self":"https://dummies-api.dummies.com/v2/categories/33607/categoryArticles?sortField=time&sortOrder=1&size=10&offset=10"},"last":{"self":"https://dummies-api.dummies.com/v2/categories/33607/categoryArticles?sortField=time&sortOrder=1&size=10&offset=89"}}},"objectTitle":"","status":"success","pageType":"article-category","objectId":"33607","page":1,"sortField":"time","sortOrder":1,"categoriesIds":[],"articleTypes":[],"filterData":{"categoriesFilter":[{"itemId":0,"itemName":"All Categories","count":99}],"articleTypeFilter":[{"articleType":"All Types","count":99},{"articleType":"Articles","count":95},{"articleType":"Cheat Sheet","count":4}]},"filterDataLoadedStatus":"success","pageSize":10},"adsState":{"pageScripts":{"headers":{"timestamp":"2025-04-17T15:50:01+00:00"},"adsId":0,"data":{"scripts":[{"pages":["all"],"location":"header","script":"<!--Optimizely Script-->\r\n<script src=\"https://cdn.optimizely.com/js/10563184655.js\"></script>","enabled":false},{"pages":["all"],"location":"header","script":"<!-- comScore Tag -->\r\n<script>var _comscore = _comscore || [];_comscore.push({ c1: \"2\", c2: \"15097263\" });(function() {var s = document.createElement(\"script\"), el = document.getElementsByTagName(\"script\")[0]; s.async = true;s.src = (document.location.protocol == \"https:\" ? \"https://sb\" : \"http://b\") + \".scorecardresearch.com/beacon.js\";el.parentNode.insertBefore(s, el);})();</script><noscript><img src=\"https://sb.scorecardresearch.com/p?c1=2&c2=15097263&cv=2.0&cj=1\" /></noscript>\r\n<!-- / comScore Tag -->","enabled":true},{"pages":["all"],"location":"footer","script":"<!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->\r\n<script type='text/javascript'>\r\n(function(){var g=function(e,h,f,g){\r\nthis.get=function(a){for(var a=a+\"=\",c=document.cookie.split(\";\"),b=0,e=c.length;b<e;b++){for(var d=c[b];\" \"==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};\r\nthis.set=function(a,c){var b=\"\",b=new Date;b.setTime(b.getTime()+6048E5);b=\"; expires=\"+b.toGMTString();document.cookie=a+\"=\"+c+b+\"; path=/; \"};\r\nthis.check=function(){var a=this.get(f);if(a)a=a.split(\":\");else if(100!=e)\"v\"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(\":\"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case \"v\":return!1;case \"r\":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(\":\")),!c}return!0};\r\nthis.go=function(){if(this.check()){var a=document.createElement(\"script\");a.type=\"text/javascript\";a.src=g;document.body&&document.body.appendChild(a)}};\r\nthis.start=function(){var t=this;\"complete\"!==document.readyState?window.addEventListener?window.addEventListener(\"load\",function(){t.go()},!1):window.attachEvent&&window.attachEvent(\"onload\",function(){t.go()}):t.go()};};\r\ntry{(new g(100,\"r\",\"QSI_S_ZN_5o5yqpvMVjgDOuN\",\"https://zn5o5yqpvmvjgdoun-wiley.siteintercept.qualtrics.com/SIE/?Q_ZID=ZN_5o5yqpvMVjgDOuN\")).start()}catch(i){}})();\r\n</script><div id='ZN_5o5yqpvMVjgDOuN'><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>\r\n<!--END WEBSITE FEEDBACK SNIPPET-->","enabled":false},{"pages":["all"],"location":"header","script":"<!-- Hotjar Tracking Code for http://www.dummies.com -->\r\n<script>\r\n (function(h,o,t,j,a,r){\r\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\r\n h._hjSettings={hjid:257151,hjsv:6};\r\n a=o.getElementsByTagName('head')[0];\r\n r=o.createElement('script');r.async=1;\r\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\r\n a.appendChild(r);\r\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\r\n</script>","enabled":false},{"pages":["article"],"location":"header","script":"<!-- //Connect Container: dummies --> <script src=\"//get.s-onetag.com/bffe21a1-6bb8-4928-9449-7beadb468dae/tag.min.js\" async defer></script>","enabled":true},{"pages":["homepage"],"location":"header","script":"<meta name=\"facebook-domain-verification\" content=\"irk8y0irxf718trg3uwwuexg6xpva0\" />","enabled":true},{"pages":["homepage","article","category","search"],"location":"footer","script":"<!-- Facebook Pixel Code -->\r\n<noscript>\r\n<img height=\"1\" width=\"1\" src=\"https://www.facebook.com/tr?id=256338321977984&ev=PageView&noscript=1\"/>\r\n</noscript>\r\n<!-- End Facebook Pixel Code -->","enabled":true}]}},"pageScriptsLoadedStatus":"success"},"navigationState":{"navigationCollections":[{"collectionId":287568,"title":"BYOB (Be Your Own Boss)","hasSubCategories":false,"url":"/collection/for-the-entry-level-entrepreneur-287568"},{"collectionId":293237,"title":"Be a Rad Dad","hasSubCategories":false,"url":"/collection/be-the-best-dad-293237"},{"collectionId":295890,"title":"Career Shifting","hasSubCategories":false,"url":"/collection/career-shifting-295890"},{"collectionId":294090,"title":"Contemplating the Cosmos","hasSubCategories":false,"url":"/collection/theres-something-about-space-294090"},{"collectionId":287563,"title":"For Those Seeking Peace of Mind","hasSubCategories":false,"url":"/collection/for-those-seeking-peace-of-mind-287563"},{"collectionId":287570,"title":"For the Aspiring Aficionado","hasSubCategories":false,"url":"/collection/for-the-bougielicious-287570"},{"collectionId":291903,"title":"For the Budding Cannabis Enthusiast","hasSubCategories":false,"url":"/collection/for-the-budding-cannabis-enthusiast-291903"},{"collectionId":299891,"title":"For the College Bound","hasSubCategories":false,"url":"/collection/for-the-college-bound-299891"},{"collectionId":291934,"title":"For the Exam-Season Crammer","hasSubCategories":false,"url":"/collection/for-the-exam-season-crammer-291934"},{"collectionId":301547,"title":"For the Game Day Prepper","hasSubCategories":false,"url":"/collection/big-game-day-prep-made-easy-301547"}],"navigationCollectionsLoadedStatus":"success","navigationCategories":{"books":{"0":{"data":[{"categoryId":33512,"title":"Technology","hasSubCategories":true,"url":"/category/books/technology-33512"},{"categoryId":33662,"title":"Academics & The Arts","hasSubCategories":true,"url":"/category/books/academics-the-arts-33662"},{"categoryId":33809,"title":"Home, Auto, & Hobbies","hasSubCategories":true,"url":"/category/books/home-auto-hobbies-33809"},{"categoryId":34038,"title":"Body, Mind, & Spirit","hasSubCategories":true,"url":"/category/books/body-mind-spirit-34038"},{"categoryId":34224,"title":"Business, Careers, & Money","hasSubCategories":true,"url":"/category/books/business-careers-money-34224"}],"breadcrumbs":[],"categoryTitle":"Level 0 Category","mainCategoryUrl":"/category/books/level-0-category-0"}},"articles":{"0":{"data":[{"categoryId":33512,"title":"Technology","hasSubCategories":true,"url":"/category/articles/technology-33512"},{"categoryId":33662,"title":"Academics & The Arts","hasSubCategories":true,"url":"/category/articles/academics-the-arts-33662"},{"categoryId":33809,"title":"Home, Auto, & Hobbies","hasSubCategories":true,"url":"/category/articles/home-auto-hobbies-33809"},{"categoryId":34038,"title":"Body, Mind, & Spirit","hasSubCategories":true,"url":"/category/articles/body-mind-spirit-34038"},{"categoryId":34224,"title":"Business, Careers, & Money","hasSubCategories":true,"url":"/category/articles/business-careers-money-34224"}],"breadcrumbs":[],"categoryTitle":"Level 0 Category","mainCategoryUrl":"/category/articles/level-0-category-0"}}},"navigationCategoriesLoadedStatus":"success"},"searchState":{"searchList":[],"searchStatus":"initial","relatedArticlesList":[],"relatedArticlesStatus":"initial"},"routeState":{"name":"ArticleCategory","path":"/category/articles/r-33607/","hash":"","query":{},"params":{"category":"r-33607"},"fullPath":"/category/articles/r-33607/","meta":{"routeType":"category","breadcrumbInfo":{"suffix":"Articles","baseRoute":"/category/articles"},"prerenderWithAsyncData":true},"from":{"name":null,"path":"/","hash":"","query":{},"params":{},"fullPath":"/","meta":{}}},"profileState":{"auth":{},"userOptions":{},"status":"success"}}
Logo
  • Articles Open Article Categories
  • Books Open Book Categories
  • Collections Open Collections list
  • Custom Solutions

Article Categories

Book Categories

Collections

Explore all collections
BYOB (Be Your Own Boss)
Be a Rad Dad
Career Shifting
Contemplating the Cosmos
For Those Seeking Peace of Mind
For the Aspiring Aficionado
For the Budding Cannabis Enthusiast
For the College Bound
For the Exam-Season Crammer
For the Game Day Prepper
Log In
  • Home
  • Technology Articles
  • Programming & Web Design Articles
  • R Articles

R Articles

R is a favorite of data scientists and statisticians everywhere, with its ability to crunch large datasets and deal with scientific information.

Articles From R

page 1
page 2
page 3
page 4
page 5
page 6
page 7
page 8
page 9
page 10

Filter Results

99 results
99 results
R R All-in-One For Dummies Cheat Sheet

Cheat Sheet / Updated 01-11-2023

R provides a wide array of functions to help you with your work — from simple statistics to complex analyses. This Cheat Sheet is a handy reference for Base R statistical functions, interactive applications, machine learning, databases, and images.

View Cheat Sheet
R R For Dummies Cheat Sheet

Cheat Sheet / Updated 07-29-2022

R is more than just a statistical programming language. It’s also a powerful tool for all kinds of data processing and manipulation, used by a community of programmers and users, academics, and practitioners. To get the most out of R, you need to know how to access the R Help files and find help from other sources. To represent data in R, you need to be able to succinctly and correctly specify subsets of your data. Finally, R has many functions that allow you to import data from other applications.

View Cheat Sheet
R R Projects For Dummies Cheat Sheet

Cheat Sheet / Updated 05-02-2022

To complete any project using R, you work with functions that live in packages designed for specific areas. This cheat sheet provides some information about these functions.

View Cheat Sheet
R Statistical Analysis with R For Dummies Cheat Sheet

Cheat Sheet / Updated 01-26-2022

R provides a wide array of functions to help you with statistical analysis with R—from simple statistics to complex analyses. Several statistical functions are built into R and R packages. R statistical functions fall into several categories including central tendency and variability, relative standing, t-tests, analysis of variance and regression analysis.

View Cheat Sheet
R How to Name Matrix Rows and Columns in R programming

Article / Updated 11-04-2021

The rbind() function in the R programming language conveniently adds the names of the vectors to the rows of the matrix. You name the values in a vector, and you can do something very similar with rows and columns in a matrix. For that, you have the functions rownames() and colnames(). Guess which one does what? Both functions work much like the names() function you use when naming vector values. Changing the row and column names The matrix baskets.team already has some row names. It would be better if the names of the rows would just read “Granny” and “Geraldine”. You can easily change these row names like this: > rownames(baskets.team) <- c(“Granny”, “Geraldine”) You can look at the matrix to check if this did what it’s supposed to do, or you can take a look at the row names itself like this: > rownames(baskets.team) [1] “Granny” “Geraldine” The colnames() function works exactly the same. You can, for example, add the number of the game as a column name using the following code: > colnames(baskets.team) <- c(“1st”, “2nd”, “3th”, “4th”, “5th”, “6th”) This gives you the following matrix: > baskets.team 1st 2nd 3th 4th 5th 6th Granny 12 4 5 6 9 3 Geraldine 5 4 2 4 12 9 This is almost like you want it, but the third column name contains an annoying writing mistake. No problem there; R allows you to easily correct that mistake. Just as the with names() function, you can use indices to extract or to change a specific row or column name. You can correct the mistake in the column names like this: > colnames(baskets.team)[3] <- “3rd” If you want to get rid of either column names or row names, the only thing you need to do is set their value to NULL. This also works for vector names, by the way. You can try that out yourself on a copy of the matrix baskets.team like this: > baskets.copy <- baskets.team > colnames(baskets.copy) <- NULL > baskets.copy [,1] [,2] [,3] [,4] [,5] [,6] Granny 12 4 5 6 9 3 Geraldine 5 4 2 4 12 9 R stores the row and column names in an attribute called dimnames. Use the dimnames() function to extract or set those values. Using names as indices These row and column names can be used just like you use names for values in a vector. You can use these names instead of the index number to select values from a vector. This works for matrices as well, using the row and column names. Say you want to select the second and the fifth game for both ladies; try: > baskets.team[, c(“2nd”, “5th”)] 2nd 5th Granny 4 9 Geraldine 4 12 Exactly as before, you get all rows if you don’t specify which ones you want. Alternatively, you can extract all the results for Granny like this: > baskets.team[“Granny”, ] 1st 2nd 3rd 4th 5th 6th 12 4 5 6 9 3 That’s the result, indeed, but the row name is gone now. R tries to simplify the matrix to a vector, if that’s possible. In this case, a single row is returned so, by default, this result is transformed to a vector. If a one-row matrix is simplified to a vector, the column names are used as names for the values. If a one-column matrix is simplified to a vector, the row names are used as names for the vector. If you want to keep all names, you must set the argument drop to FALSE to avoid conversion to a vector.

View Article
R How to Create a Data Frame from Scratch in R

Article / Updated 10-28-2021

In the R programming language, a conversion from a matrix to a data frame can’t be used to construct a data frame with different types of values. If you combine both numeric and character data in a matrix, for example, everything will be converted to character. You can construct a data frame from scratch, though, using the data.frame() function. Once a data frame is created, you can add observations to a data frame. Make a data frame from vectors in R So, let’s make a little data frame with the names, salaries, and starting dates of a few imaginary co-workers. First, you create three vectors that contain the necessary information like this: > employee <- c('John Doe','Peter Gynn','Jolie Hope') > salary <- c(21000, 23400, 26800) > startdate <- as.Date(c('2010-11-1','2008-3-25','2007-3-14')) Now you have three different vectors in your workspace: A character vector called employee, containing the names A numeric vector called salary, containing the yearly salaries A date vector called startdate, containing the dates on which the co-workers started Next, you combine the three vectors into a data frame using the following code: > employ.data <- data.frame(employee, salary, startdate) The result of this is a data frame, employ.data, with the following structure: > str(employ.data) 'data.frame': 3 obs. of 3 variables: $ employee : Factor w/ 3 levels "John Doe","Jolie Hope",..: 1 3 2 $ salary : num 21000 23400 26800 $ startdate: Date, format: "2010-11-01" "2008-03-25" ... To combine a number of vectors into a data frame, you simply add all vectors as arguments to the data.frame() function, separated by commas. R will create a data frame with the variables that are named the same as the vectors used. Keep characters as characters in R You may have noticed something odd when looking at the structure of employ.data. Whereas the vector employee is a character vector, R made the variable employee in the data frame a factor. R does this by default, but you have an extra argument to the data.frame() function that can avoid this — namely, the argument stringsAsFactors. In the employ.data example, you can prevent the transformation to a factor of the employee variable by using the following code: > employ.data <- data.frame(employee, salary, startdate, stringsAsFactors=FALSE) If you look at the structure of the data frame now, you see that the variable employee is a character vector, as shown in the following output: > str(employ.data) 'data.frame': 3 obs. of 3 variables: $ employee : chr "John Doe" "Peter Gynn" "Jolie Hope" $ salary : num 21000 23400 26800 $ startdate: Date, format: "2010-11-01" "2008-03-25" ... By default, R always transforms character vectors to factors when creating a data frame with character vectors or converting a character matrix to a data frame. This can be a nasty cause of errors in your code if you’re not aware of it. If you make it a habit to always specify the stringsAsFactors argument, you can avoid a lot of frustration.

View Article
R Standard Deviation in R

Article / Updated 09-30-2019

After you calculate the variance of a set of numbers, you have a value whose units are different from your original measurements. For example, if your original measurements are in inches, their variance is in square inches. This is because you square the deviations before you average them. So the variance in the five-score population in the preceding example is 6.8 square inches. It might be hard to grasp what that means. Often, it's more intuitive if the variation statistic is in the same units as the original measurements. It's easy to turn variance into that kind of statistic. All you have to do is take the square root of the variance. Like the variance, this square root is so important that it is has a special name: standard deviation. Population standard deviation The standard deviation of a population is the square root of the population variance. The symbol for the population standard deviation is Σ (sigma). Its formula is For this 5-score population of measurements (in inches): 50, 47, 52, 46, and 45 the population variance is 6.8 square inches, and the population standard deviation is 2.61 inches (rounded off). Sample standard deviation The standard deviation of a sample — an estimate of the standard deviation of a population — is the square root of the sample variance. Its symbol is s and its formula is For this sample of measurements (in inches): 50, 47, 52, 46, and 45 the estimated population variance is 8.4 square inches, and the estimated population standard deviation is 2.92 inches (rounded off). Using R to compute standard deviation As is the case with variance, using R to compute the standard deviation is easy: You use the sd() function. And like its variance counterpart, sd() calculates s, not Σ: > sd(heights) [1] 2.915476 For Σ — treating the five numbers as a self-contained population, in other words — you have to multiply the sd() result by the square root of (N-1)/N: > sd(heights)*(sqrt((length(heights)-1)/length(heights))) [1] 2.607681 Again, if you're going to use this one frequently, defining a function is a good idea: sd.p=function(x){sd(x)*sqrt((length(x)-1)/length(x))} And here's how you use this function: > sd.p(heights) [1] 2.607681

View Article
R R Project: Combining an Image with an Animated Image

Article / Updated 04-11-2018

If you’ve been working with images, animated images, and combined stationary images in R, it may be time to take the next step. This project walks you through the next step: Combine an image with an animated image. This image shows the end product — the plot of the iris data set with comedy icons Laurel and Hardy positioned in front of the plot legend. When you open this combined image in the Viewer, you see Stan and Ollie dancing their little derbies off. (The derbies don’t actually come off in the animation, but you get the drift.) Getting Stan and Ollie Check out the Laurel and Hardy GIF. Right-click the image and select Save Image As from the pop-up menu that appears. Save it as animated-dancing-image-0243 in your Documents folder. Then read it into R: l_and_h <- image_read("animated-dancing-image-0243.gif") Applying the length() function to l_and_h > length(l_and_h) [1] 10 indicates that this GIF consists of ten frames. To add a coolness factor, make the background of the GIF transparent before image_read() works with it. This free online image editor does the job quite nicely. Combining the boys with the background If you use the image combination technique, the code looks like this: image_composite(image=background, composite_image=l_and_h, offset = "+510+200") The picture it produces looks like the image above but with one problem: The boys aren’t dancing. Why is that? The reason is that image_composite() combined the background with just the first frame of l_and_h, not with all ten. It’s exactly the same as if you had run image_composite(image=background, composite_image=l_and_h[1], offset = "+510+200") The length() function verifies this: > length(image_composite(image=background, composite_image=l_and_h, offset = "+510+200")) [1] 1 If all ten frames were involved, the length() function would have returned 10. To get this done properly, you have to use a magick function called image_apply(). Explaining image_apply() So that you fully understand how this important function works, let's describe an analogous function called lapply(). If you want to apply a function (like mean()) to the variables of a data frame, like iris, one way to do that is with a for loop: Start with the first column and calculate its mean, go to the next column and calculate its mean, and so on until you calculate all the column means. For technical reasons, it’s faster and more efficient to use lapply() to apply mean() to all the variables: > lapply(iris, mean) $Sepal.Length [1] 5.843333 $Sepal.Width [1] 3.057333 $Petal.Length [1] 3.758 $Petal.Width [1] 1.199333 $Species [1] NA A warning message comes with that last one, but that’s okay. Another way to write lapply(iris, mean) is lapply(iris, function(x){mean(x)}). This second way comes in handy when the function becomes more complicated. If, for some reason, you want to square the value of each score in the data set and then multiply the result by three, and then calculate the mean of each column, here’s how to code it: lapply(iris, function(x){mean(3*(x^2))}) In a similar way, image_apply() applies a function to every frame in an animated GIF. In this project, the function that gets applied to every frame is image_composite(): function(frame){image_composite(image=background, composite_image=frame, offset = "+510+200")} So, within image_apply(), that’s frames <- image_apply(image=l_and_h, function(frame) { image_composite(image=background, composite_image=frame, offset = "+510+200") }) After you run that code, length(frames) verifies the ten frames: > length(frames) [1] 10 Getting back to the animation The image_animate() function puts it all in motion at ten frames per second: animation <- image_animate(frames, fps = 10) To put the show on the screen, it’s print(animation) All together now: l_and_h <- image_read("animated-dancing-image-0243.gif") background <- image_background(iris_plot, "white) frames <- image_apply(image=l_and_h, function(frame) { image_composite(image=background, composite_image=frame, offset = "+510+200") }) animation <- image_animate(frames, fps = 10) print(animation) And that’s the code for the image above. One more thing. The image_write() function saves the animation as a handy little reusable GIF: image_write(animation, "LHirises.gif")

View Article
R 11 Useful Resources for R Programmers

Article / Updated 04-11-2018

Here, you learn about books and websites that help you learn more about R programming. Without further ado. . . Interacting with users If you want to delve deeper into R applications that interact with users, start with this tutorial by shiny guiding force Garrett Grolemund. For a helpful book on the subject, consider Chris Beeley’s web Application Development with R Using Shiny, 2nd Edition (Packt Publishing, 2016). Machine learning For the lowdown on all things Rattle, go directly to the source: Rattle creator Graham Williams has written Data Mining with Rattle and R: The Art of Excavating Data for Knowledge Discovery (Springer, 2011). Check out the companion website. The University of California-Irvine Machine Learning Repository plays such a huge role in the R programming world. Here’s how its creator prefers that you look for the material: Lichman, M. (2013). UCI Machine Learning Repository [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California, School of Information and Computer Science. Thank you, UCI Anteaters! If machine learning interests you, take a comprehensive look at the field (under its other name, “statistical learning”): Gareth James, Daniela Witten, Trevor Hastie, and Robert Tibshirani’s An Introduction to Statistical Learning with Applications in R (Springer, 2017). An Introduction to Neural Networks, by Ben Krose and Patrick van der Smagt, is a little dated, but you can get it for the low, low price of nothing: After you download a large PDF, it’s a good idea to upload it into an ebook app, like Google Play Books. That turns the PDF into an ebook and makes it easier to navigate on a tablet. Databases The R-bloggers website has a nice article on working with databases. Of course, R-bloggers has terrific articles on a lot of R-related topics! You can learn quite a bit about RFM (Recency Frequency Money) analysis and customer segmentation at www.putler.com/rfm-analysis. Maps and images The area of maps is a fascinating one. You might be interested in something at a higher level. If so, read Introduction to visualising spatial data in R by Robin Lovelace, James Cheshire, Rachel Oldroyd (and others). David Kahle and Hadley Wickham’s ggmap: Spatial Visualization with ggplot2 is also at a higher level. Fascinated by magick? The best place to go is the primary source. Check it out.

View Article
R R Project: Delay and Weather

Article / Updated 04-11-2018

Try out this R project to see how one variable might affect an outcome. It’s conceivable that weather conditions could influence flight delays. How do you incorporate weather information into the assessment of delay? One nycflights13 data frame called weather provides the weather data for every day and hour at each of the three origin airports. Here’s a glimpse of exactly what it has: > glimpse(weather,60) Observations: 26,130 Variables: 15 $ origin "EWR", "EWR", "EWR", "EWR", "EWR", "... $ year 2013, 2013, 2013, 2013, 2013, 2013, ... $ month 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... $ day 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... $ hour 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 1... $ temp 37.04, 37.04, 37.94, 37.94, 37.94, 3... $ dewp 21.92, 21.92, 21.92, 23.00, 24.08, 2... $ humid 53.97, 53.97, 52.09, 54.51, 57.04, 5... $ wind_dir 230, 230, 230, 230, 240, 270, 250, 2... $ wind_speed 10.35702, 13.80936, 12.65858, 13.809... $ wind_gust 11.918651, 15.891535, 14.567241, 15.... $ precip 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... $ pressure 1013.9, 1013.0, 1012.6, 1012.7, 1012... $ visib 10, 10, 10, 10, 10, 10, 10, 10, 10, ... $ time_hour 2012-12-31 19:00:00, 2012-12-31 20:... So the variables it has in common with flites_name_day are the first six and the last one. To join the two data frames, use this code: flites_day_weather <- flites_day %>% inner_join(weather, by = c("origin","year","month","day","hour","time_hour")) Now you can use flites_day_weather to start answering questions about departure delay and the weather. What questions will you ask? How will you answer them? What plots will you draw? What regression lines will you create? Will scale() help? And, when you’re all done, take a look at arrival delay (arr_delay).

View Article
page 1
page 2
page 3
page 4
page 5
page 6
page 7
page 8
page 9
page 10

Quick Links

  • About For Dummies
  • Contact Us
  • Activate Online Content

Connect

About Dummies

Dummies has always stood for taking on complex concepts and making them easy to understand. Dummies helps everyone be more knowledgeable and confident in applying what they know. Whether it's to pass that big test, qualify for that big promotion or even master that cooking technique; people who rely on dummies, rely on it to learn the critical skills and relevant information necessary for success.

Copyright @ 2000-2024 by John Wiley & Sons, Inc., or related companies. All rights reserved, including rights for text and data mining and training of artificial technologies or similar technologies.

Terms of Use
Privacy Policy
Cookies Settings
Do Not Sell My Personal Info - CA Only