Introduction
Sometimes, working with a dataset requires you to create rounded versions of a variable. In this blog, we’ll show you how to use R to round numbers.
Rounding
It’s a good idea to leave your original variable—the one to be rounded—alone and to generate new rounded versions of that variable.
Try the following commands:
x<-runif(5, min=0, max=100)
x1<-round(x)
x2<-round(x, digits=1)
x3<-round(x, digits=2)
x4<-round(x, digits=3)
print(x)
print(x1)
print(x2)
print(x3)
print(x4)
The first variable, x, consists of 5 random numbers from 0 to 100. Next, x1 rounds x to an integer, and x2, x3, and x4 consist of rounded versions of x to 1, 2, and 3 digits, respectively. Here’s what it all looks like in R Studio.
BridgeText can help you with all of your statistical analysis needs.