Introduction to R and Python
Learn how to set up R and RStudio on your machine. We will also demonstrate how to install R packages from CRAN, and install the tidyverse package.
Welcome
This tutorial introduces both R and Python programming, covering fundamental topics such as data types, variables, operators, and loops. Use the tabs below to switch between R and Python content.
Data Types in R
- Integer: Whole numbers (e.g.,
42
,-3
) - Double/Floating Point: Decimal numbers (e.g.,
3.14
,-2.718
) - Character (String): Text in quotes (e.g.,
"Hello World"
) - Logical (Boolean):
TRUE
,FALSE
- Missing Values:
NA
,NaN
# Examples of Data Types in R
<- 42 # Integer
x <- 3.14 # Floating point
y <- "Hello, R!" # String
z <- TRUE # Boolean
is_valid print(c(x, y, z, is_valid))
Variables in R
<- 10
a <- 5
b <- a + b # Addition
c print(c) # Output: 15
Data Types in Python
- Integer: Whole numbers (
42
,-3
) - Float: Decimal numbers (
3.14
,-2.718
) - String: Text in quotes (
"Hello World"
) - Boolean:
True
,False
# Examples of Data Types in Python
= 42 # Integer
x = 3.14 # Float
y = "Hello, Python!" # String
z = True # Boolean
is_valid print(x, y, z, is_valid)
Variables in Python
= 10
a = 5
b = a + b # Addition
c print(c) # Output: 15
Loops
Loops allow us to execute a block of code multiple times, reducing repetition and making our programs more efficient. The two most common types of loops are:
- For loops: Used when we know how many times we need to iterate.
- While loops: Used when we repeat execution until a condition is met.
Below are examples of loops in R and Python: