Introduction to Markdowns
Markdown is a lightweight text formatting system that uses plain characters (like # or *) to create styled text such as headings, bold, italics, and lists. It’s popular because it’s simple, readable in plain text, and shareable.
Your words go directly in the document, written as plain Markdown text.
Your code goes inside a code chunk, which is a separate block inserted with the shortcut:
Windows: Press Ctrl + Alt + I
Mac: Press Cmd + Option + I
Or, use the menu option Insert (the green “c” square above your script.
From set = {2, 14, 15, 0, 7, 36}, pick two numbers and perform the following operations:
#Addition
14+15
## [1] 29
#Subtraction
15-7
## [1] 8
#Multiplication
15*36
## [1] 540
#Division (Try dividing by zero, what do you get?)
14/7
## [1] 2
36/0
## [1] Inf
#Exponentiation
7^2
## [1] 49
#Square Root
sqrt(36)
## [1] 6
Suppose you have a set of numbers representing the temperatures (in degrees Celsius) recorded over a week:
temperatures <- c(23.5, 21.8, 25.2, 20, 22.7, 19.5, 24.0)
#Calculate the Total Temperature.
sum(temperatures)
## [1] 156.7
#Find the Average Temperature.
mean(temperatures)
## [1] 22.38571
#Use the round(x, n) function to round the average temperature to two decimal places.
round(mean(temperatures),2)
## [1] 22.39
#Find the Maximum and Minimum Temperatures
max(temperatures)
## [1] 25.2
min(temperatures)
## [1] 19.5
#Problem 3: Using logical Operators and Indexing
You are organizing a school event, and you need to categorize students based on their ages. Here’s the students’ages:
ages <- c(22, 18, 25, 30, 16, 20, 19, 21, 24, 18)
#Find the fifth element in"ages"
ages[5]
## [1] 16
#Identify Ages Older than 21: Use the > operator to identify ages older than 21.
ages[ages>21]
## [1] 22 25 30 24
#Identify Ages Younger than 20: Use the < operator to identify ages younger than 20.
ages[ages<20]
## [1] 18 16 19 18
#Identify Ages Not Equal to 18: Use the != operator to identify ages not equal to 18.
ages[ages!=18]
## [1] 22 25 30 16 20 19 21 24
# Identify ages that are not equal to 18, 22, or 25
ages[!(ages %in% c(18, 22, 25))]
## [1] 30 16 20 19 21 24
#Identify Ages Equal to 25: Use the == operator to identify ages equal to 25.
ages[ages==25]
## [1] 25
# Count how many are equal to 25
length(ages[ages==25])
## [1] 1