Mastering the Basics of R Programming and Navigating RStudio

Welcome back to our fourth tutorial! In this post, we will be teaching you how to use basic R commands and navigate RStudio. If you’re joining us, we have a project file open with an R markdown file, which you can follow by checking out our YouTube channel @cradletograver.

Recommended Books

To further enhance your understanding of R programming and data manipulation, we recommend the following books (as an Amazon Associate, I may earn a small commission from these links):

  1. R for Data Science: Import, Tidy, Transform, Visualize, and Model Data
  2. Ace the Data Science Interview: 201 Real Interview Questions Asked By FAANG, Tech Startups, & Wall Street
  3. The Kaggle Book: Data analysis and machine learning for competitive data science
  4. Practical Statistics for Data Scientists: 50+ Essential Concepts Using R and Python

Understanding Vectors in R

In R, a vector is a sequence of elements of the same type, such as numbers or bits of text, but not a combination of both. The power of R is that most functions can use a vector directly as input, which simplifies coding in many applications because you avoid using for loops.

To create a vector, we can use the c() function. For example:

number1 <- c(1, 3, 4, 7, 10, 11)

This will create a vector called number1 with the given elements.

Useful Functions with Vectors

With vectors, we can perform various operations and use different functions. Some of them are:

  • sum(): Calculate the sum of the elements in a vector.
  • mean(): Calculate the mean (average) of the elements in a vector.
  • length(): Find the number of elements in a vector.
  • min(): Find the minimum value in a vector.
  • max(): Find the maximum value in a vector.
  • unique(): Extract the unique values in a vector.
  • sort(): Sort the elements of a vector.

For example, to find the sum of the elements in number1, we can use the sum() function:

sum(number1)

This will return the sum of the elements in number1.

Random Facts about R

  1. Ross Ihaka and Robert Gentleman created R at the University of Auckland, New Zealand, and is an implementation of the S programming language.
  2. R is open-source software that is freely available and can be modified and redistributed.
  3. Statisticians, data scientists, and researchers widely use R for statistical analysis, visualization, and machine learning tasks.

More on R Functions

In R, functions can have default values for their arguments. For example, the round() function has an argument called digits with a default value of 0. If you want to round a number to a certain number of decimal places, you can override the default value by specifying the digits argument:

round(3.14159, digits = 2)

This will return the value of 3.14.

To learn more about a function and its arguments, start typing the function name and opening the parenthesis. A yellow box will pop up with information about the function’s arguments and their default values.

Recommended Resources

To dive deeper into R programming and its applications, check out these books:

  1. Machine Learning with R
  2. Extending Power BI with Python and R: Ingest, transform, enrich, and visualize data using the power of analytical languages
  3. The Book of R – A First Course in Programming and Statistics

We hope you found this tutorial helpful! Please comment below and subscribe to our YouTube channel to stay updated with more videos like this.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *