R

In this post, I will share some knowledge about the R programming language that has been studied before, during the EHASP period at the Faculty of Medicine, Padjadjaran University. Enjoy reading!

Overview of R

R is one of the programming languages that is often used in analyzing data, especially in terms of data manipulation and visualization. By using R, we can do various things to data, such as adding data variables with certain functions, changing data variables with a certain function, creating a diagram of data, and so on. We can do those things by writing certain commands in a script, then running or executing it.

To get R, you can download it here. Make sure to download the R version that corresponds to your device’s Operating System (OS).

RStudio

To make it easier for us to use R, both to write commands on the script, and to run the script itself, we can use an application that is integrated with the R programming language, that is RStudio. Using RStudio, we can write commands on R script and run or execute it with a friendlier and easier-to-understand user interface (UI) design. In addition, the R script that we have created can also be saved through RStudio so that we can open the R script at any time.

To get RStudio, you can download it here. Make sure you have:

  • download the version of RStudio corresponding to your device’s OS; and
  • download and install the R programming language first before running RStudio.

R Package

In addition to RStudio which can make it easier for us to use R, other features can also make it easier for us to analyze data using R, which are packages. A package has various special functions that usually focus on an aspect of data processing, such as the ggpplot2 package which mainly serves for the data visualization process.

Thus, the process of data analysis by using R will have wider limitations, especially with R packages that can be developed by everyone, even today there are already more than 16,000 packages available on R. However, how do we access and use those packages?

We don’t need to worry about that because in RStudio these packages can be directly downloaded and installed, even the information of each function available on a particular package can be directly seen. This convenience is caused by the R package stored in a library system and archived directly on the R website itself so that it can be directly accessed by everyone.

Basic Syntax of R

As a programming language, R has its own rules in making a command with various functions so that it can be run later. This rule is known as syntax which is also found in other programming languages, such as Python and SQL.

To create a command or script that can be run, we need to know three basic things related to the R syntax. By understanding these three things, we will more easily understand the characteristics of R.

Variables are like a place to store data. We can create/assign/define a variable with a specific name to various data, such as vector, numeric, character, data frame, and others. To create a variable, we can associate the variable name with the desired data using three denotations:

  • = for simple assignment;
  • <- for left assignment; and
  • -> for right assignment.

Example:

var_1 = "Simple definition."
var_2 <- "Left assignment."
"Right assignment." -> var_3

print(var_1)
print(var_2)
print(var_3)

Output:

[1] Simple definition.
[2] Left assignment.
[3] Right assignment.

A comment is a sentence written to make it easier to read certain codes or commands. The comments are only intended for us so R will not run or execute them and do not produce output. Usually, comments use the denotation of the hashtag # at the beginning of the sentence.

Example:

# This is a comment.
print("Hello, world!")

Output:

[1] Hello, world!

Keywords are special words stored with special functions that can be a command or parameters. We can see the R keyword by using the help(reserved) or ?reserved commands. Take a look at the image below that shows examples of keywords in R.

R Keywords - javatpoint
Keywords in R. (Source: Javatpoint)

Note: This post is not completely finished and will continue to be updated. Thank you!