R-1ST Internal-Lab Notes
R-1ST Internal-Lab Notes
complex_var <- 4 + 5i
Integer variable: 42
# Vector
# Matrix
cat("Matrix:\n")
print(matrix_var)
cat("\n")
# Array
print(array_var)
cat("\n")
# Data Frame
ID = 1:3,
cat("Data Frame:\n")
print(data_frame_var)
cat("\n")
# List
Vector = vector_var,
Matrix = matrix_var,
DataFrame = data_frame_var
cat("List:\n")
print(list_var)
cat("\n")
# Factor
OUTPUT:
Vector:
12345
Matrix:
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
Array:
,,1
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
,,2
[,1] [,2]
[1,] 7 10
[2,] 8 11
[3,] 9 12
Data Frame:
ID Name Age
1 1 Alice 25
2 2 Bob 30
3 3 Charlie 35
List:
$Vector
[1] 1 2 3 4 5
$Matrix
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
$Data Frame
ID Name Age
1 1 Alice 25
2 2 Bob 30
3 3 Charlie 35
Factor:
…………………………………………………………………………
…………………………………………………………
3.Write a R program to take input from the user (name, age,
address, city, state) and display the values. Also, print the
# Taking user inputs for name, age, address, city, and state
is:\n")
cat(R.version.string, "\n")
OUTPUT:
Age: 25
City: Springfield
State: IL
……………………………………………………
……………………………………………………
……………………………………..
# Arithmetic Operators
num1 <- 10
num2 <- 5
cat("Arithmetic Operators:\n")
Remainder of division
division result
# Relational Operators
cat("Relational Operators:\n")
cat("Is num1 greater than num2? ", num1 > num2, "\n")
cat("Is num1 less than num2? ", num1 < num2, "\n")
num2, "\n")
cat("Is num1 less than or equal to num2? ", num1 <= num2,
"\n\n")
# Logical Operators
cat("Logical Operators:\n")
cat("AND (num1 > 5 and num2 < 10): ", (num1 > 5) &
cat("OR (num1 > 5 or num2 > 10): ", (num1 > 5) | (num2 >
10), "\n")
# Assignment Operators
cat("Assignment Operators:\n")
x <- 20
y <- 30
# Miscellaneous Operators
cat("Miscellaneous Operators:\n")
n")
OUTPUT:
Arithmetic Operators:
Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2
Exponentiation: 100000
Modulus (remainder): 0
Integer Division: 2
Relational Operators:
Logical Operators:
Assignment Operators:
x assigned value: 20
y assigned value: 30
x after x += 5: 25
y after y -= 5: 25
Miscellaneous Operators:
# Create a 4 × 4 matrix
print(my_matrix)
matrix_sum, "\n")
Explanation:
4 × 4 Matrix:
[1,] 1 5 9 13
[2,] 2 6 10 14
[3,] 3 7 11 15
[4,] 4 8 12 16
……………………………………………………
……………………………………………………
…………………………