- ?(<function name>)
- help(<function name>)
For example
Once you type help (type) it will display the detailed description of type function in the help window as below,
Setting and getting Working Directory in R
The working directory is the location of our computer where our script related to R, codes, files and all other stuff is stored. It helps us generally to work fast when we work with read and write operations as these operations require file path, for example, reading Excel data in R. If the file which we want to access is in the same directory, then no full path is required it only require the file name to be read.
To set the working location of use setwd() function. For e.g.,
To get the location of the working directory, we use getwd() function. For e.g.,
Comment in R
It is an important part of the code which is used for documentation. Although it is not executable yet it helps others to understand the code we have done. So, every language supports this functionality. For commenting R code, we use # sign before it.
Datatypes and Variable in R
R language supports a wide range of datatypes like numeric, integers, logical, character, list, matrices, vector, etc. We shall discuss it later in another article.
Working with Variables in R
In R variables datatype is assigned automatically runtime as per the value assigned to it. To assign a value in any variable we use sign <-. However, we can use = operator also to assign a varible in R.
Below are some of the variables used with basic operations performed.
Checking Datatype of Variables in R
To know the datatype of the variable just we use the typeof() function in R. Below images are the example of typeof() function.
Creating our own function in R
We use keyword function for creating a function in R. The syntax is very simple just give the name of the function with the assignment operator. The below screen illustrates how to create a function in R. Here, Addition, Subtraction, Multiplication, and Division are the name of functions. All these functions have two parameters named a and b.
Calling a function in R
To call a function just type the name of the function with their parameter values. For example, calling the above functions is as simple as it has been shown in below image.
To make a parameter optional you can assign it while creating a function. For example, it has been shown in the below image. Here, we have passed only the value of a and b is assigned automatically as 10.
Concatenating two strings or characters in R
We use paste function for concatenating two string or characters. You can use it as in below image.
Summary
In this article, we have learned the basics of R programming language. We have also learned some important functions like setwd(), getwd(), help(), paste() and print(). Apart from this, we have also learned how to create and call our own functions in R.
Hope you have learned and enjoyed reading this article. You’re welcome to like, comment, share and any type of suggestion for my appreciation.