Certainly! In R, you can find the maximum and minimum values in a dataset or a vector using the max()
and min()
functions, respectively.
Example: Suppose we have a vector of numbers representing daily temperatures in Celsius for a week:
Example
# Daily temperatures in Celsius
temperatures <- c(20, 22, 25, 18, 23, 21, 24)
# Find the maximum temperature
max_temp <- max(temperatures)
print(paste("Maximum temperature:", max_temp, "Celsius"))
# Find the minimum temperature
min_temp <- min(temperatures)
print(paste("Minimum temperature:", min_temp, "Celsius"))
In this example:
temperatures
containing daily temperatures for a week.max()
function to find the maximum temperature in the temperatures
vector and store it in the variable max_temp
.min()
function to find the minimum temperature in the temperatures
vector and store it in the variable min_temp
.When you run this code, it will print the maximum and minimum temperatures for the week.