# Define variables with different data types
a <- 42
string <- "Hello, World!"
logic <- TRUE
date_time <- as.POSIXct("2004-10-04 14:30:00")
# Print variables
cat("Numeric Variable:",a, "\n")
## Numeric Variable: 42
print("The character variable is:")
## [1] "The character variable is:"
print(string)
## [1] "Hello, World!"
print("The logical variable is:")
## [1] "The logical variable is:"
print(logic)
## [1] TRUE
cat("Date and Time Variable:", date_time, "\n")
## Date and Time Variable: 1096880400
# Create data structures
vector1<- c(1, 2, 3, 4, 50,43,32)
matrix1<- matrix(1:9, nrow = 3, ncol = 3)
list1 <- list(04, "SriManikanta", FALSE)
data_frame<- data.frame(
Name = c("Karthik", "Yaswitha", "Abhinaya","Vishnu","Pranay"),
Age = c(20,20,23,45,44),
Score = c(91, 81, 55,100,11)
)
# Print data structures
print(vector1)
## [1] 1 2 3 4 50 43 32
print("Matrix Example")
## [1] "Matrix Example"
print(matrix1)
## [,1] [,2] [,3]
## [1,] 1 4 7
## [2,] 2 5 8
## [3,] 3 6 9
print("List Example")
## [1] "List Example"
print(list1)
## [[1]]
## [1] 4
##
## [[2]]
## [1] "SriManikanta"
##
## [[3]]
## [1] FALSE
print("The dataframe is:")
## [1] "The dataframe is:"
print(data_frame)
## Name Age Score
## 1 Karthik 20 91
## 2 Yaswitha 20 81
## 3 Abhinaya 23 55
## 4 Vishnu 45 100
## 5 Pranay 44 11
# b.Create a vector
vector5 <- c(2, 4, 6, 8, 10)
sum_result <- sum(vector5)
mean_result <- mean(vector5)
product_result <- prod(vector5)
# Print the results
print(paste("Sum:", sum_result))
## [1] "Sum: 30"
print(paste("Product:", product_result))
## [1] "Product: 3840"
# c.Create a vector
my_vector <- c(3, 1, 7, 2, 9)
# Find the minimum and maximum
min_value <- min(my_vector)
max_value <- max(my_vector)
# Print the results
print(paste("Minimum:", min_value))
## [1] "Minimum: 1"
# c.Create a vector
my_vector <- c(3, 1, 7, 2, 9)
# Find the minimum and maximum
min_value <- min(my_vector)
max_value <- max(my_vector)
# Print the results
print(paste("Minimum:", min_value))
## [1] "Minimum: 1"
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.