R current times still giving you that itch to try something new? R you currently missing out on learning a great scripting language? You R in luck! We’ve got an opportunity that’s too good to pass up! In case you missed the puns, R is a popular scripting language that can add another notch in your analysis and data mining belt. At Technomics, we use it to crunch larger data sets, perform statistical analyses, and build beautiful dashboards to help our clients make better decisions from their data, faster!  Plus, R’s software is 100% free to download. Convinced you should learn more? Great!

But where do you start?

We’ve laid out some background, reasoning, and starter functions to get you going. But again, this is just a start! Our experienced practitioners love to talk shop. Technomics has conducted targeted R training sessions for a variety of clients from short introductions to multi day courses. We’d love to help you out wherever you are with R – feel free to get in touch by leaving a comment on LinkedIn or Twitter!

What is R? 

r-project.org
r-project.org

Put simply, R is a powerful scripting language centered around data. At its core, R is a statistical package that excels at tasks such as regression analysis and plotting.

Why Use R?

1. Large User Base

R is very popular in the data science community.

2. Extensive (and Growing) Library of Packages

Popularity has led to R becoming a go-to for manipulating data sets, machine learning, and even the development of interactive dashboards.

3. Effective Data Handling and Storage Facility1

R is able to read in, manipulate, and store data from many formats such as XLXS, CSV, XML, JSON and TXT.

4. Well-Designed, Publication-Quality Visuals1

Create graphs and charts like a pro with built-in graphics that allow for user customization.

5. Seamless Teamwork

Combine R with products like RStudio and GitLab to work in a multi user-friendly environment.

 

Starter Functions in R

1. help()

What does it do?

help() gives you documentation on any function in R. This documentation includes a description, use cases, arguments, references, and examples for the function.

When do you use it?

You just downloaded R’s software and installed a bunch of packages that have some functions. But you don’t want to dig deep into a dictionary to figure out what these functions do! You want answers now! And the help() function is here to make that happen. Use help() any time you need to learn more about a function!

Shortcut

Instead of taking the time to type out help(), place a ? in front of the function name you need help with.

 

2. class()

What does it do?

class() displays an object’s type.

When do you use it?

In R, an object can be many types - including character, numeric, logical, and many more. Unfortunately, you can give an object the wrong type just as easily as a making a spelling error. Even worse, R will sometimes still run even if the typing on an object is wrong. This can really mess up your results and make it hard to find the problem! Thankfully, class() comes in to quickly help the problem. Use class() on any object that you’d like to study in your code. Especially if R gives the object an error. Using class() is also a great way double check your objects!

Bonus function

You identified that your object has the wrong type. Now it’s time to resolve the issue! How? With as()! . For instance, let’s say R identifies your object of the number “1” as a character. But you can’t mathematically compute a character type! Change it to a numeric with as.numeric(“1”). Here’s a sample of class types using as():

  • as.character()
  • as.numeric()
  • as.logical()
  • as.Date()
  • as.data.frame()

Note: Don’t forget the period (“.”)!

 

3. plot()

What does it do?

plot() visualizes your data by placing it on a simple graph.

When do you use it?

You’ve found yourself scrolling through multiple, long data sets in Excel, and you’re not too interested in taking the time to create a new Excel graphic for each data set. You want a quick look at what every data set has to offer! Use plot() in R to get the job done! Quickly store each variable from your data sets as R objects and use plot() to display the story behind your data.

Customize your graph

A quick use of plot() would look similar to plot(“x-axis object”, “y-axis object”). For presenting the data to others, you may consider some modifications. Here are some arguments you can add within plot() to make your graph fit your style:

  • type: Allows you to choose how your data looks when plotted. Some of these types are “p” for data points, “l” for lines, and “b” to see both points and lines. By default, R will display only points.
  • main: Allows you to give your graph a main title.
  • xlab/ylab: Allows you to give your respective axes a title.

Example

Here is a visual showing a mock data set to determine the miles per gallon of a car. The x-axis object is “gallons” and the y-axis object is “miles”. plot() is used with the following customization:

References:

1. https://www.r-project.org/about.html