Menu

R Basics: Variables, Data Types and Operators

R Basics

Variables and Data Types

A variable is a name that stores a value. In R, you create one with the arrow symbol. Choose clear names such as student_marks, and avoid spaces.

The four main data types are:

  • Numeric: Numbers with decimals.
  • Integer: Whole numbers.
  • Character: Text.
  • Logical: TRUE or FALSE.

The class() function tells you the type of any value.

Operators and Expressions

Operators are symbols that perform actions. Arithmetic operators do maths, including addition, subtraction, multiplication, division, power, and remainder.

Comparison operators compare values and return TRUE or FALSE, for example, greater than or equal to. Logical operators join conditions: & means AND, | means OR, and ! means NOT.

An expression is any combination of values and operators that R can calculate.

Type Conversion and Basic Functions

Sometimes data arrives as the wrong type. For example, the number 42 may arrive as text. Conversion functions fix this.

Some basic functions you will use often are length(), sum(), mean(), round(), and str(). The str() function shows the structure of any object, which is very helpful for beginners.


R for Data Science

HA

Harini A



Learn via Video Course

Data Analysis and Processing with Python using Pandas - Data Science Course Logo

Data Analysis and Processing with Python using Pandas - Data Science Course

5 hrs



Get in Touch For Details