R can be easily downloaded and installed from the CRAN website.
You can select a suitable operating system and click on it to download. Here, “Download R for Windows” has been selected.
Follow the default options to finish the installation.
You can also install RStudio, which is an integrated development environment for R. It is available in two formats: RStudio Desktop is a regular desktop application. At the same time, RStudio Server runs on a remote server and enables RStudio access using a web browser.
The following is what the interface of RStudio looks like:
Here is a small script that is used to perform some basic operations and plot a graph.
Before you start programming in R, you should install packages and their dependencies. Packages provide pre-assembled collections of functions and objects. Each package is hosted on the CRAN repository. Not all packages are loaded by default, but they can be installed on demand.
To install a new package in RStudio, go to Tools -> Install Packages
Then, you can search for the package you want to install and select the location where you want to install the package.
Now, let’s discuss the different data structures available in the R programming language.
1. Vectors: It is the most basic R object, which has atomic values.
2. Matrices: These are R objects in which the elements are arranged in a two-dimensional layout. They also contain elements of the same types.
3. Arrays: They can store data in more than two dimensions. Suppose we create an array of dimensions (two, three, four) then it creates four rectangular matrices, each with two rows and three columns.
4. Data Frames: A data frame is a table in which each column contains values of one variable, and each row contains one set of values from each column.
5. Lists: A list contains elements of different types (numbers, strings, vectors, etc.) It can also include a matrix or a function as its elements. The list is created using the list() function.