iris <- read.csv('c:\\datafile\\iris2.csv',stringsAsFactors = T)
iris
normalize <- function(x){
return ((x - min(x))/(max(x) - min(x)))
}
iris_n <- as.data.frame(lapply(iris['Sepal.Length'],normalize))
iris_n
iris2 <- cbind(iris[,c('Species','Sepal.Length')],iris_n)
names(iris2) <- c('Species','Sepal.Length','after_Sepal.Length')
summary(iris2)
hist_before <- ggplot(iris2, aes(x = Sepal.Length)) +
geom_histogram(binwidth = 1, fill = 'blue', alpha = 0.7) +
ggtitle("Before Sepal.Length Min-Max Normalization") +
theme_minimal()
hist_after <- ggplot(iris2, aes(x = after_Sepal.Length)) +
geom_histogram(binwidth = 0.05, fill = 'red', alpha = 0.7) +
ggtitle("After Sepal.Length Min-Max Normalization") +
theme_minimal()
library(gridExtra)
grid.arrange(hist_before, hist_after, ncol = 2)