Scaling or Normalizing the column in R

Scaling or Normalizing the column in R is accomplished using scale() function. Let’s see how to scale or normalize the column of a dataframe with an example.

Let’s first create the dataframe.

df1 = data.frame(Name = c('George','Andrea', 'Micheal','Maggie','Ravi','Xien','Jalpa'), 
                 Mathematics_score=c(45,78,44,89,66,49,72),
                 Science_score=c(56,52,45,88,33,90,47))
df1

So the resultant dataframe will be

Scaling or Normalizing the column in R 1

 

Scaling or normalizing the column in R:

We will be normalizing Mathematics_score as shown below

df1$mathematics_score_normalized = scale(df1$Mathematics_score)
df1

So the normalized column will be

Scaling or Normalizing the column in R 2

Scaling or Normalizing the column in R - image previous-small-11-1 on http://www.datasciencemadesimple.com                                                                                                          Scaling or Normalizing the column in R - image next_small-11-1 on http://www.datasciencemadesimple.com