Rounding off the column in R

Rounding off the column in R can be accomplished by using round() function. In this tutorial we will see how to

  • Round off the column to integer
  • Round off the column to some decimal places

Let’s first create the dataframe

df1 = data.frame(State = c('Arizona AZ','Georgia GG', 'Newyork NY','Indiana IN','Florida FL'), Score=c(62.345,47.734,55.867,74.256,31.901))
df1

df1 will be

Rounding off the column in R 1

 

Round off the column to integer

round() function simply round offs the column to integer

df1$Round_off <- round(df1$Score) # Round off the column to integer
df1

Rounded off integer will be

Rounding off the column in R 2

 

Round off the column to decimal places

round() function along with digit arguments rounds off the column to specified decimal places

df1$Round_off <- round(df1$Score ,digit=2) # Round off the column for 2 decimal
df1

Rounds off to two decimal places

Rounding off the column in R 3

                                                                                                           

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.