Search
  • Linda Stewart

Analytic Sets Access: Step Two in Learning R Programming for Free

I hope you are enjoying Performance Architects’ “Learning R Programming for Free” blog post series. In the first post in this series, I discussed how to install the free R tool from CRAN and a simple example of using the R interpreter to calculate the tip on a restaurant bill.

In this segment, I introduce some ways to access analytic sets to use in your learning.  When we installed the R tool, we selected the “base” link.  What we installed was “base R.”

Developers have created all sorts of additional functionality accessible from GitHub and CRAN.  Since we do not necessarily need all functions right now, we can add what we need by adding packages.  The first package we will look at is “dslabs.”

At the “R Console” prompt, type:

install.packages (“dslabs”)


You will be prompted to select a “Mirror.”  We selected “NY.”

In the install of the package, we will see that we get the following functionality:

package ‘glue’ successfully unpacked and MD5 sums checked package ‘magrittr’ successfully unpacked and MD5 sums checked package ‘stringi’ successfully unpacked and MD5 sums checked package ‘colorspace’ successfully unpacked and MD5 sums checked package ‘assertthat’ successfully unpacked and MD5 sums checked package ‘fansi’ successfully unpacked and MD5 sums checked package ‘utf8’ successfully unpacked and MD5 sums checked package ‘Rcpp’ successfully unpacked and MD5 sums checked package ‘stringr’ successfully unpacked and MD5 sums checked package ‘labeling’ successfully unpacked and MD5 sums checked package ‘munsell’ successfully unpacked and MD5 sums checked package ‘R6’ successfully unpacked and MD5 sums checked package ‘RColorBrewer’ successfully unpacked and MD5 sums checked package ‘cli’ successfully unpacked and MD5 sums checked package ‘crayon’ successfully unpacked and MD5 sums checked package ‘pillar’ successfully unpacked and MD5 sums checked package ‘digest’ successfully unpacked and MD5 sums checked package ‘gtable’ successfully unpacked and MD5 sums checked package ‘lazyeval’ successfully unpacked and MD5 sums checked package ‘plyr’ successfully unpacked and MD5 sums checked package ‘reshape2’ successfully unpacked and MD5 sums checked package ‘rlang’ successfully unpacked and MD5 sums checked package ‘scales’ successfully unpacked and MD5 sums checked package ‘tibble’ successfully unpacked and MD5 sums checked package ‘viridisLite’ successfully unpacked and MD5 sums checked package ‘withr’ successfully unpacked and MD5 sums checked package ‘ggplot2’ successfully unpacked and MD5 sums checked package ‘dslabs’ successfully unpacked and MD5 sums checked

To use the package, we type in the name of the library surrounded in double quotes and parentheses:

(“dslabs”).


A better development tool for this is “R IDE”. RStudio can be downloaded here.  RStudio is a great tool for editing and testing your code. If we open RStudio, we see this:


Notice our “dslabs” package is shown at the R console prompt (in our left-hand window).

Let’s extend our knowledge of R with some simple concepts.  To solve equations, we need to be able to make assignments just like we did in high school when we learned algebra.

To make an assignment, we use the “<-“ characters.  The characters form an arrow pointing towards the variable name. Let’s assign a few values (we show the R prompt in red, no need to type that):

> m <- 10 > n <- -1 > p <- 2 > pi <- 3.14

To print the variable’s value, type the variable name:> m [1] 10 > n [1] -1 > p [1] 2 > pi [1] 3.14If we like, we can also use the print function to write out the value of a variable:

> print(m) [1] 10 > print(n) [1] -1 > print(p) [1] 2 > print(pi) [1] 3.14

If we want to see what variables have assigned values in our workspace, we can use the “ls” function:

> ls() [1] “m”  “n”  “p”  “pi”

In our next installment, I will discuss how to apply functions like square root to variables and how to read the internals of a function.

Additional blog posts on more complex R concepts to follow; please contact communications@performancearchitects.com if you have any questions or need further help!

#installingR #Rprogramming #LearningR #BusinessIntelligence #datascience

Computer%20with%20Graph_edited.jpg

BLOGS

© 2006 - 2020 by Performance Architects

  • Facebook
  • Twitter
  • LinkedIn
  • YouTube