## Getting Started with R Cheat Sheet

R is one of the most popular programming languages in data science and is widely used across various industries and in academia. Given that it’s open-source, easy to learn, and capable of handling complex data and statistical manipulations, R has become the preferred computing environment for many data scientists today.

This cheat sheet will provide an overview of getting started with R. Use it as a handy, high-level reference for a quick start with R.

## Try this Cheat Sheet with DataCamp Workspace

We designed this cheat sheet with the hope of showing what is possible in R. As such, we wanted you to get a first-hand experience in trying out the different functions and terms mentioned in this cheat sheet.

### Working with Objects in R

```
# Returns the structure and information of a given object
str(list(1,2,3)) # This returns a list alongside the numbers in the list
str("Hello World") # This returns a character alongside the contents of the string
```

```
# Returns the class of a given object
class("Hello World")
class(list(1,2,3))
```

### Using Packages in R

R packages are collections of functions and tools developed by the R community. They increase the power of R by improving existing base R functionalities, or by adding new ones.

```
# Install tidyverse — Workspace comes pre-installed with all top R packages, so you can skip this step ;)
install.packages("tidyverse")
```

```
# Load packages in R
library(tidyverse)
```

### The Working Directory

The working directory is a file path that R will use as the starting point for relative file paths. That is, it's the default location for importing and exporting files. An example of a working directory looks like `”C://file/path"`

```
# Returns your current working directory
getwd()
```

```
# Changes your current working directory to a desired file path
setwd('/work/files/workspace/')
```

### Operators in R

R has multiple operators that allow you to perform a variety of tasks.

#### Arithmetic Operators in R

Arithmetic operators let you perform arithmetic such as addition and multiplication.

```
# + lets you sums two variables
1 + 2
```

```
# - lets you subtract two variables
2 - 1
```