WHAT IS R- STUDIO
R Studio is an integrated development environment(IDE) for R. IDE is a
GUI, where we can write your quotes, see the results and also see the
variables that are generated during the course of programming.
R Studio is available as both Open source and Commercial software.
R Studio is also available as both Desktop and Server versions.
R Studio is also available for various platforms such as Windows,
Linux, and macOS.
Getting Started with R Studio
Rstudio is an open-source tool that provides Ide to use R language, and
enterprise-ready professional software for data science teams to develop
share the work with their team.
R Studio can be downloaded from its official Website ([Link]
and instructions for installation are available on How to Install RStudio
for R programming in Windows?
After the installation process is over, the R Studio interface looks
like:
R Studio
The Console panel (left panel) is where R waits for us to enter
commands. This is the area where we write our code and see the
output immediately.
On the top right, we have the Environment/History panel.
The Environment tab shows all the variables that have been created
during our programming session.
The History tab keeps track of all the commands we’ve used so far in
our current session.
On the bottom right, there is another panel that contains several useful
tabs.
The Files tab displays the files and folders in the current working
directory.
The Plots tab is used to display graphs and plots that we generate
through our R scripts.
The Packages tab shows all the installed packages and allows us to
install new ones.
The Help tab provides documentation and support for R functions.
The Viewer tab is used to view local web content generated within R.
Features of R Studio
A friendly user interface
writing and storing reusable programmes
All imported data and newly created objects (such as variables,
functions, etc.) are easily accessible.
Comprehensive assistance for any item Code autocompletion
The capacity to organise and share your work with your partners more
effectively through the creation of projects.
Plot snippets
Simple terminal and console switching
Tracking of operational history
There are numerous articles from RStudio Support on using the IDE.
Set the working directory in R Studio
R is always pointed at a directory on our computer. We can find out
which directory by running the getwd() function. Note: this function has
no arguments. We can set the working directory manually in two ways:
The first way is to use the console and using the command
setwd("directorypath").
You can use this function setwd() and give the path of the directory
which you want to be the working directory for R studio, in the
double codes.
The second way is to set the working directory from the GUI.
To set the working directory from the GUI you have to click on this 3
dots button. When you click this, this will open up a file browser,
which will help you to choose your working directory.
R Studio
Once you choose your working directory, you need to use this setting
button in the more tab and click it and then you get a popup menu,
where you need to select "Set as working directory".
This will select the current directory, which you have chosen using this
file browser as your working directory. Once you set the working
directory, you are ready to program in R Studio.
Create an RStudio project
Step 1: Select the FILE option and select create option.
Step 2: Then select the New Project option.
Step 3: Then choose the path and directory name.
Finally, project are created in a specific location:
Navigating directories in R studio
getwd(): Returns the current working directory.
setwd(): Set the working directory.
dir(): Return the list of the directory.
sessionInfo(): Return the session of the windows.
date(): Return the current date.
Creating your first R script
Here we are adding two numbers in R studio.
How to Perform Various Operations in RStudio
We'll see some common tasks, their codes in R Studio
Installing R packages
Syntax:
[Link]('package_name')
Loading R package
Syntax:
library(package_name)
Help on an R package
help(package_name)
R Studio, a versatile R IDE, supports open-source and commercial usage
on various platforms. It streamlines data science tasks, from project
creation to package management, with a user-friendly interface.
1. Variables in R
This problem can be solved by using variables which like any other
programming language are the name given to reserved memory locations
that can store any type of data. In R, the assignment can be denoted in
three ways:
1. = (Simple Assignment)
2. <- (Leftward Assignment)
3. -> (Rightward Assignment)
Example:
Output:
"Simple Assignment"
"Leftward Assignment!"
"Rightward Assignment"
The rightward assignment is less common and can be confusing for
some programmers, so it is generally recommended to use the <- or =
operator for assigning values in R.
2. Comments in R
Comments are a way to improve your code's readability and are only
meant for the user so the interpreter ignores it. Only single-line
comments are available in R but we can also use multiline comments by
using a simple trick which is shown below. Single line comments can be
written by using # at the beginning of the statement.
Example:
Output:
[1] "This is fun!"
From the above output, we can see that both comments were ignored by
the interpreter.
3. Keywords in R
Keywords are the words reserved by a program because they have a
special meaning thus a keyword can't be used as a variable name,
function name, etc. We can view these keywords by using either
help(reserved) or ?reserved.
if, else, repeat, while, function, for, in, next and break are used for
control-flow statements and declaring user-defined functions.
The ones left are used as constants like TRUE/FALSE are used as
boolean constants.
NaN defines Not a Number value and NULL are used to define an
Undefined value.
Inf is used for Infinity values.
R-Data Types
Last Updated : 12 Jul, 2025
Data types in R define the kind of values that variables can hold.
Choosing the right data type helps optimize memory usage and
computation. Unlike some languages, R does not require explicit data
type declarations while variables can change their type dynamically
during execution.
R Programming language has the following basic R-data types and the
following table shows the data type and the values that each data type
can take.
Basic Data Types Values Examples
Set of all real "numeric_value <-
Numeric numbers 3.14"
Integer Set of all integers, Z "integer_value <- 42L"
"logical_value <-
TRUE and FALSE
Logical TRUE"
Basic Data Types Values Examples
Set of complex "complex_value <- 1 +
Complex numbers 2i"
"a", "b", "c", ..., "@",
"character_value <-
"#", "$", ...., "1", "2",
"Hello Geeks"
Character ...etc
"single_raw <-
[Link]()
raw [Link](255)"
1. Numeric Data type in R
Decimal values are called numeric in R. It is the default R data type for
numbers in R. If we assign a decimal value to a variable x as follows, x
will be of numeric type.
Real numbers with a decimal point are represented using this data type
in R. It uses a format for double-precision floating-point numbers to
represent numerical values.
x = 5.6
print(class(x))
print(typeof(x))
Output
[1] "numeric"
[1] "double"
Even if an integer is assigned to a variable y, it is still saved as a
numeric value.
y=5
print(class(y))
print(typeof(y))
Output
[1] "numeric"
[1] "double"
When R stores a number in a variable, it converts the number into a
"double" value or a decimal type with at least two decimal places.
This means that a value such as "5" here, is stored as 5.00 with a type
of double and a class of numeric. And also y is not an integer here can
be confirmed with the [Link]() function.
y=5
print([Link](y))
Output
[1] FALSE
2. Integer Data type in R
R supports integer data types which are the set of all integers. we can
create as well as convert a value into an integer type using
the [Link]() function.
we can also use the capital 'L' notation as a suffix to denote that a
particular value is of the integer R data type.
x = [Link](5)
print(class(x))
print(typeof(x))
y = 5L
print(class(y))
print(typeof(y))
Output
[1] "integer"
[1] "integer"
[1] "integer"
[1] "integer"
3. Logical Data type in R
R has logical data types that take either a value of true or false. A
logical value is often created via a comparison between variables.
Boolean values, which have two possible values, are represented by
this R data type: FALSE or TRUE
x=4
y=3
z=x>y
print(z)
print(class(z))
print(typeof(z))
Output
[1] TRUE
[1] "logical"
[1] "logical"
4. Complex Data type in R
R supports complex data types that are set of all the complex numbers.
The complex data type is to store numbers with an imaginary
component.
x = 4 + 3i
print(class(x))
print(typeof(x))
Output
[1] "complex"
[1] "complex"
5. Character Data type in R
R supports character data types where we have all the alphabets and
special characters. It stores character values or strings. Strings in R can
contain alphabets, numbers, and symbols.
The easiest way to denote that a value is of character type in R data
type is to wrap the value inside single or double inverted commas.
char = "Geeksforgeeks"
print(class(char))
print(typeof(char))
Output
[1] "character"
[1] "character"
There are several tasks that can be done using R data types. Let's
understand each task with its action and the syntax for doing the task
along with an R code to illustrate the task.
6. Raw data type in R
To save and work with data at the byte level in R, use the raw data
type. By displaying a series of unprocessed bytes, it enables low-level
operations on binary data. Here are some speculative data on R's raw
data types:
x <- [Link](c(0x1, 0x2, 0x3, 0x4, 0x5))
print(x)
Output
[1] 01 02 03 04 05
Five elements make up this raw vector x, each of which represents a
raw byte value.
Find Data Type of an Object in R
To find the data type of an object we have to use class() function. The
syntax for doing that is we need to pass the object as an argument to the
function class() to find the data type of an object.
Syntax
class(object)
Example
print(class(TRUE))
print(class(3L))
print(class(10.5))
print(class(1+2i))
print(class("12-04-2020"))
Output
[1] "logical"
[1] "integer"
[1] "numeric"
[1] "complex"
[1] "character"
Type verification
We can verify the data type of an object, if we doubt about it's data
type. To do that, we need to use the prefix "is." before the data type as a
command.
Syntax
is.data_type(object)
Example
print([Link](TRUE))
print([Link](3L))
print([Link](10.5))
print([Link](1+2i))
print([Link]("12-04-2020"))
print([Link]("a"))
print([Link](2+3i))
Output
[1] TRUE
[1] TRUE
[1] TRUE
[1] TRUE
[1] TRUE
[1] FALSE
[1] FALSE
Coerce or Convert the Data Type of an Object to Another
The process of altering the data type of an object to another type is
referred to as coercion or data type conversion. This is a common
operation in many programming languages that is used to alter data and
perform various computations. When coercion is required, the language
normally performs it automatically, whereas conversion is performed
directly by the programmer.
Coercion can manifest itself in a variety of ways, depending on the R
programming language and the context in which it is employed. In
some circumstances, the coercion is implicit, which means that the
language will change one type to another without the programmer
having to expressly request it.
Syntax
as.data_type(object)
Note: All the coercions are not possible and if attempted will be
returning an "NA" value.
For Detailed Explanation - Data Type Conversion in R
Example
print([Link](TRUE))
print([Link](3L))
print([Link](10.5))
print([Link](1+2i))
print([Link]("12-04-2020"))
Output
[1] 1
[1] 3+0i
[1] TRUE
[1] "1+2i"
[1] NA
Warning message:
In print([Link]("12-04-2020")) : NAs introduced by coercion