Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
How to Normalize Data in R?
Next article icon

How to Normalize Data in R?

Last Updated : 01 Aug, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will discuss how to normalize data in the R programming language.

What is Normalization?

Normalization is a pre-processing stage of any type of problem statement. In particular, normalization takes an important role in the field of soft computing, cloud computing, etc. for the manipulation of data, scaling down, or scaling up the range of data before it becomes used for further stages. There are so many normalization techniques there, namely Min-Max normalization, Z-score normalization, and Decimal scaling normalization.

What is Data Normalization?

Data transformation operations, such as normalization and aggregation, are additional data preprocessing procedures that would contribute toward the success of the data extraction process.

Data normalization consists of remodeling numeric columns to a standard scale. Data normalization is generally considered the development of clean data.

Method 1: Normalize data with log transformation in base R

In this approach to normalize the data with its log transformation, the user needs to call the log() which is an inbuilt function, and pass the data frame as its parameter to transform the given data to its log and the resulting data will then be transformed to the scale.

log() function is used to compute logarithms, by default natural logarithms.

Syntax:

log(x)

Parameters:

  • x: a numeric or complex vector.

Example: Normalize data 

R
# Create data gfg <- c(244, 753, 596, 645, 874, 141,           639, 465, 999, 654)  # normalizing data gfg1 <-log(gfg) gfg1 

Output:

 [1] 5.497168 6.624065 6.390241 6.469250 6.773080 4.948760 6.459904 6.142037 6.906755
[10] 6.483107

Method 2: Normalize Data with Standard Scaling in R

In this method to normalize the data, the user simply needs to call the scale() function which is an inbuilt function, and pass the data which is needed to be scaled, and further, this will be resulting in normalized data from range -1 to 1 in the R programming language.

Scale() is a generic function whose default method centers and/or scales the columns of a numeric matrix.

Syntax:

scale(x)

Parameters:

  • x: Data

Example: Normalize data

R
# Create data gfg <- c(244,753,596,645,874,141,639,465,999,654)  # normalizing data gfg <- as.data.frame(scale(gfg))  gfg 

Output:

            V1
1 -1.36039519
2 0.57921588
3 -0.01905315
4 0.16766775
5 1.04030220
6 -1.75289016
7 0.14480397
8 -0.51824578
9 1.51663105
10 0.20196343

Method 3: Normalize Data using Min-Max Scaling

In this method to normalize, the user has to first install and import the caret package in the R working console, and then the user needs to call the preProcess() function with the method passed as the range as its parameters, and then the user calls the predict() function to get the final normalize data which will lead to the normalization of the given data to the scale from 0 to 1 in the R programming language.

preprocess () function is used for transformation can be estimated from the training data and applied to any data set with the same variables.

Syntax:

preProcess(x,method)

Parameters:

  • x: Data
  • method: a character vector specifying the type of processing.

Example: Normalize data

R
library(caret)  # Create data gfg <- c(244,753,596,645,874,141,639,465,999,654)  # normalizing data ss <- preProcess(as.data.frame(gfg), method=c("range"))  gfg <- predict(ss, as.data.frame(gfg)) gfg 

Output:

         gfg
1 0.1200466
2 0.7132867
3 0.5303030
4 0.5874126
5 0.8543124
6 0.0000000
7 0.5804196
8 0.3776224
9 1.0000000
10 0.5979021

Method 4: Normalize Data using Z-Score Standardization

In statistics, the task is to standardize variables which is called evaluating z-scores. Comparing two standardizing variables is the function of standardizing vector. By subtracting the vector by its mean and dividing the result by the vector’s standard deviation we can standardize a vector.

R
# Input vector gfg <- c(244, 753, 596, 645, 874, 141, 639, 465, 999, 654)  # Z-score standardization gfg_standardized <- (gfg - mean(gfg)) / sd(gfg)  # View the standardized vector print(gfg_standardized) 

Output:

 [1] -1.36039519  0.57921588 -0.01905315  0.16766775  1.04030220 -1.75289016
[7] 0.14480397 -0.51824578 1.51663105 0.20196343

Next Article
How to Normalize Data in R?

G

geetansh044
Improve
Article Tags :
  • R Language

Similar Reads

    How to Normalize Data in Excel?
    The term "normalization" is a popular buzzword among professionals in fields like Machine Learning, Data Science, and statistics. It refers to the process of scaling down values to fit within a specific range. The term is often misunderstood and is sometimes used interchangeably with "standardisatio
    7 min read
    How to Normalize and Standardize Data in R?
    In this article, we will be looking at the various techniques to scale data,  Min-Max Normalization, Z-Score Standardization, and Log Transformation in the R programming language. Loading required packages and dataset: Let's install and load the required packages. And also create a dataframe as a sa
    5 min read
    How to Test for Normality in R
    Normality testing is important in statistics since it ensures the validity of various analytical procedures. Understanding whether data follows a normal distribution is critical for drawing appropriate conclusions and predictions. In this article, we look at the methods and approaches for assessing
    4 min read
    Normalize Data in MATLAB
    Data Normalization is a technique in statistical mathematics that converts the entire data into a specified range or scale or normalizes it using different methods such as by computing its z-score. There is no specific definition of normalization but, it has various meanings depending on the user's
    2 min read
    How to Code in R programming?
    R is a powerful programming language and environment for statistical computing and graphics. Whether you're a data scientist, statistician, researcher, or enthusiast, learning R programming opens up a world of possibilities for data analysis, visualization, and modeling. This comprehensive guide aim
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences