Getting ready with R

Getting ready with R

Fundamentals of R

~R is a platform for statistical computing that is open source and free. Millions of users, including you and me, contribute daily to R to handle statistical data analysis. As it's a component of a new project, we can download and utilize it free of charge. It follows a slightly different course because it is not GUI-based but rather is an environmental language that runs from the command line. You can select a mirror site in R from among the many available mirror sites for downloading R. R is easy to download on any operating system, including Linux, Windows, and macOS.

~Download and install R

Currently, the R that you have installed is base R. It comes with a lot of strength when we download it, and 100 developers are also working on various packages to work in the flexible environment of R. So, each time we want to use R packages, we must install and library them.

There are task views that allow us to see the many types of packages that are available in R languages and learn more about them. The R instructions on their website are well structured.

~R studio

R studio is an Integrated development environment (IDE) for R. It is initially designed to create turnkey R projects, however for those of us who use R studio for routine analysis, this R studio is helpful. It is better to work with R Studio; download R Studio by visiting its website and scrolling down to download the desktop edition of R Studio.

You can Download Both R and R studio here(https://posit.co/download/rstudio-desktop/))

~Let's start with R

When we open R after a successful installation, a window known as the R console appears. The greater than (>) symbol is located next to the command entry field in the R console.

Let's hit Ctrl L to clear up the console's plenty of information before entering our first command. Ask R to calculate the square root of nine.

Once you press Enter, 3 has been calculated.

Let's add a new variable, a = 3

It displays a value for a

Give Y the value that X represents.

As we know, computer programming only understands numerical things, hence the error here means that object y is not present.

Hence, each time I say "a=3," we receive the value of a.

~R script

A script is nothing more than a collection of R commands. For example, let's say we need to write numerous commands to perform regression analysis on a huge set of data. If we write the same programming codes repeatedly when performing regression on different sets of data, we risk making mistakes. Here, we may create a script with all the commands for a certain example, store it as a separate file, and then load and run the script whenever we want to participate in a similar investigation.

~Chage dir

Set the directory where you wish to work and read files in R every time. Let's set a directory in Windows (c:) for a file called "First code in R" as an example.

• Open R's change dir command and choose the file.

•in Windows, create a new folder (c:)

The directory has been set.

~R editor

The R Editor, where we may enter our command, is displayed whenever we open a new R console. It is usually a good idea to write comments before a command to explain why and for what goals we are writing it. Let's say I want to create a series that runs from 1 to 10.

#store a sequence of numbers in x

Write >x and check the results of the previous command.

It has produced a list of numbers in ascending order.

Take y, a further variable and make a plot. Before running the plot, we should save the file in the directory that we already set. Let's plot the x-vs-y data.

This x vs. y plot is quadratic since y = x square, as can be seen.

We can work in this manner.

~advantages of R script

If, after a few days, we decide to use the file we've already saved, we can do so by going to the R console.

•Open the file in the R console and run it, or

•We can also run R by opening the file in a certain directory, selecting everything with Ctrl-A, and running it.

This is a straightforward example of how to utilize R script. If you need to change it later, you can do so by giving it a new name.

~Let me take you through R studio

There are several panes when we launch R Studio; the lower pane is the R console and the upper one is the R script. After setting the directory, we can simply open the file (firstcodeinR) in R and run it.

There are 10 values of x, according to the right-hand side window where we can examine our data. Let's run the second line; instead of repeatedly pressing run, we can use "alt enter" concurrently.

y is put into action.

Let's repeat the same process in R Studio and practice it ^_^

Â