# create a vector
data1 = c(34, 54, 25, 5, 34, 65, 43)

# find the minimum value
print(min(data1))
## [1] 5
# find the maximum value
print(max(data1))
## [1] 65
# create a dataframe
data2=data.frame(col1=c(3,24,26,51),
                col2=c("Ellie","Joel","Can","Kath"),
                col3=c(4.3,1.6,6.8,7.3))

# the minimum value in first column
print(min(data2$col1))
## [1] 3
# the minimum value in second column
print(min(data2$col2))
## [1] "Can"
# the minimum value in third column
print(min(data2$col3))
## [1] 1.6
# the maximum value in first column
print(max(data2$col1))
## [1] 51
# the maximum value in second column
print(max(data2$col2))
## [1] "Kath"
# the maximum value in third column
print(max(data2$col3))
## [1] 7.3
# create a dataframe
data3=data.frame(col1=c(3,24,26,51),
                col2=c("Ellie","Joel","Can","Kath"),
                col3=c(4.3,1.6,6.8,7.3))

# the minimum value across dataframe
print(sapply(data3, min))
##  col1  col2  col3 
##   "3" "Can" "1.6"
# the maximum value across dataframe
print(sapply(data3, max))
##   col1   col2   col3 
##   "51" "Kath"  "7.3"
# create a dataframe
data4=data.frame(col1=c(3,24,26,51),
                col2=c("Ellie","Joel","Can","Kath"),
                col3=c(4.3,1.6,6.8,7.3))

# the minimum value in multiple columns of dataframe
print(min(c(data4$col1,data4$col2,data4$col3)))
## [1] "1.6"
# the maximum value in multiple columns of dataframe
print(max(c(data4$col1,data4$col2,data4$col3)))
## [1] "Kath"
# maximum function for a numeric vector with NA
data5 <-c(4.3,1.6,6.8,7.3,NA)
max(data5)
## [1] NA
# maximum function for a numeric vector with removing NA
data5 <-c(4.3,1.6,6.8,7.3,NA)
max(data5, na.rm=TRUE)
## [1] 7.3
# minimum function for a numeric vector with NA
data6 <-c(4.3,1.6,6.8,7.3,NA)
min(data5)
## [1] NA
# minimum function for a numeric vector with NA
data6 <-c(4.3,1.6,6.8,7.3,NA)
min(data5, na.rm=TRUE)
## [1] 1.6
# maximum function for a character vector
data7<-c("i","q","a","x")
max(data7)
## [1] "x"
# minimum function for a character vector
data7<-c("i","q","a","x")
min(data7)
## [1] "a"
# Maximum function of character vector names
data8 <- c('Ellie','Joel','Can','Kath')
max(data8)
## [1] "Kath"
# Minimum function of character vector names
data8 <- c('Ellie','Joel','Can','Kath')
min(data8)
## [1] "Can"
#practical example How to know the highest and lowest price
### create dataframe 
Shop = data.frame(Items = c("Fruit","Fruit","Fruit","Fruit","Fruit","Vegetable","Vegetable","Vegetable",
                                  "Vegetable","Fruit","Fruit","Vegetable","Vegetable"), 
                       I_Names = c("Apple","Banana","Orange","Mango","Papaya","Carrot","Potato","Brinjal",
                                     "Raddish","Peach","Stawberries","Cabbage","Greenchilli"),
                       Price = c(100,80,80,90,65,70,60,70,25,60,40,50,20),
                       Tax = c(2,4,5,6,2,3,5,1,3,4,5,4,3))
Shop
#Columns
# maximum value of a column in dataframe
 max(Shop$Price)
## [1] 100
# minimum value of a column in dataframe
 min(Shop$Price)
## [1] 20
# maximum value of multiple columns in data frame 
 mapply(max,Shop[,c(-1,-2)])
## Price   Tax 
##   100     6
# minimum value of multiple columns in data frame 
 mapply(min,Shop[,c(-1,-2)])
## Price   Tax 
##    20     1
# maximum value of the column by group 
aggregate(x= Shop$Price,by= list(Shop$Items), FUN=max)
# minimum value of the column by group 
aggregate(x= Shop$Price,by= list(Shop$Items), FUN=min)