1. Simple calculation
#1. Addition, subtraction, multiplication, division
3 + 4
## [1] 7
4 - 5
## [1] -1
7 * 8
## [1] 56
8 / 3
## [1] 2.666667
#2.
a <- 7
b = 8
c = a + b
c
## [1] 15
#3.
pi
## [1] 3.141593
#4. Power
5^3
## [1] 125
2. Vector
x <- c(1, 3, 4, 5, 6, 7, 8, 2, 10) # create a vector consisits of these numbers..
sum(x)
## [1] 46
y <- c(3, 5, 2)
sum(y^2)
## [1] 38
z <- c(1:10)
z
## [1] 1 2 3 4 5 6 7 8 9 10
3. seq (sequence), rep (repetition), gl(generating levels)
# seq
x <- (1:12)
x
## [1] 1 2 3 4 5 6 7 8 9 10 11 12
y <- (8:5)
y
## [1] 8 7 6 5
z <- seq(4, 7, 0.5)
z
## [1] 4.0 4.5 5.0 5.5 6.0 6.5 7.0
# rep
a = rep(11, 3)
a
## [1] 11 11 11
rep(c(1:5), 3)
## [1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
rep(c(1.1, 1.2, 1.3), 2)
## [1] 1.1 1.2 1.3 1.1 1.2 1.3
# gl
gl(2, 8)
## [1] 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2
## Levels: 1 2
gl(3, 5)
## [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
## Levels: 1 2 3
4. Create R script
5. Create R markdown and up load
6. Examples
# Print a greeting
print("Hello, R!")
## [1] "Hello, R!"
# Assign values to variables
x <- 5
y <- 10
# Perform operations with variables
z <- x + y
print(z)
## [1] 15
# Create a vector
numbers <- c(1, 2, 3, 4, 5)
print(numbers)
## [1] 1 2 3 4 5
# Access elements of a vector
print(numbers[1])
## [1] 1
# Perform summary statistics on a vector
mean_val <- mean(numbers)
print(mean_val)
## [1] 3
# Plot a graph
plot(numbers)

# Create a data frame
fruit <- c("apple", "banana", "cherry")
count <- c(10, 20, 30)
fruit_count <- data.frame(fruit, count)
# Print the data frame
print(fruit_count)
## fruit count
## 1 apple 10
## 2 banana 20
## 3 cherry 30
# Subset the data frame
bananas <- fruit_count[fruit_count$fruit == "banana", ]
print(bananas)
## fruit count
## 2 banana 20
# Perform summary statistics on a column of a data frame
mean_count <- mean(fruit_count$count)
print(mean_count)
## [1] 20
# Plot a bar graph
barplot(fruit_count$count, names.arg = fruit_count$fruit,
main = "Fruit Count", xlab = "Fruit", ylab = "Count")
