 # 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):

## 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`.

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: