Bytes
rocket

Your Success, Our Mission!

6000+ Careers Transformed.

R Console and Scripts

Last Updated: 20th August, 2026

The R Console is where R executes commands immediately. When you type a command and press Enter, R processes it and shows the output.

Example:

23

Output appears instantly in the console.

Use cases of Console:

  • Quick calculations
  • Testing small pieces of code
  • Exploring data interactively

However, console commands are not saved automatically.

An R Script is a file (with .R extension) where you write and save R code.

Advantages of scripts:

  • Code is saved for future use
  • Improves reproducibility
  • Easier debugging and collaboration

Example script:

x <- 10
y <- 5
x + y

Best practice:
Use scripts for actual analysis and the console for quick testing.

Variables and Data Types

Variables store values in memory. R commonly uses the assignment operator <-.

Example:

age <- 21
name <- "alex"

You can also use = but <- is preferred in R programming.

The different Data Types in R are :

  1. Numeric – decimal values
height <- 5.8
  1. Integer – whole numbers
count <- 10
  1. Character – text values
city <- "Mumbai"
  1. Logical – TRUE or FALSE
is_student <- TRUE

We can check a variable’s type using:

class(age)

Understanding data types is crucial because R behaves differently based on the type of data.

Operators in R

Operators allow R to perform computations and comparisons.

1. Arithmetic Operators

Used for mathematical calculations.

Operator

Meaning

+Addition
-Subtraction
*Multiplication
/Division
^Power

Example:

105
23

2. Relational Operators

Used for comparisons.

Operator

Meaning

>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to
==Equal to
!=Not equal to

Example:

age > 18

3. Logical Operators

Logical operators are used to combine, compare, or negate conditions. They always return a logical value: TRUE or FALSE.

Operator

Name

Description

Example

!Logical NOTFlips the result (TRUE to FALSE)!(5 == 5)
&Element-wise ANDTRUE if both conditions are TRUE x > 5 & x < 10
|Element-wise ORTRUE if at least one is TRUEx == 1 | x == 2
&&Logical ANDTRUE if both conditions are TRUE (single comparison)if (a && b)
||Logical ORTRUE if one is TRUE (single comparison)if(a || b)

Example:

age > 18 & is_student == TRUE

4. Assignment Operator

Used to assign values:

x <- 100
Module 3: R Basics and SyntaxR Console and Scripts

Top Tutorials

Logo
Computer Science

CNN in Deep Learning 2026

A beginner-friendly guide to CNNs: understand deep learning essentials, create Python-based models, and explore advanced applications.

4 Modules12 Lessons189 Learners
Start Learning
Logo
Computer Science

Breaking The Limits: Scaling Databases with MySQL Partitioning

Learn MySQL partitioning with examples. Improve query performance, scalability, and data management using RANGE, LIST, HASH, KEY, and composite techniques.

7 Modules11 Lessons91 Learners
Start Learning
Logo

ML in Action: Hands-On Guide to Deploying and Serving Models

Learn model deployment and serving—from concepts to real-world architectures, tools, APIs, containers, and cloud workflows for production-ready ML.

3 Modules6 Lessons91 Learners
Start Learning
  • Official Address
  • 4th floor, 133/2, Janardhan Towers, Residency Road, Bengaluru, Karnataka, 560025
  • Communication Address
  • Follow Us
  • facebook
    instagram
    linkedin
    twitter
    youtube
    telegram

© 2026 AlmaBetter