Compute a Sequence of Equally Spaced Round values in R Programming – pretty() Function
pretty() function in R Language is used to decide sequence of equally spaced round values.
Syntax: pretty(x, n) Parameters: x: It is defined as vector data n: length of resultant vector Returns: data vector of equal length interval
Example 1:
Output:
[1] 0 10 20 30 40 50
Example 2:
r
x <- 1:50
pretty (x, n = 10)
|
Output:
[1] 0 5 10 15 20 25 30 35 40 45 50
Here n = 10 states that the interval vector consisting of ten intervals, i.e. n+1 elements. Example 3:
r
x <- 1:50
y <- 1:50
plot (x, y,
main = " Axis Labels")
|
Output:
Example :
R
x <- seq (0, 10, length.out = 100)
y <- sin (x)
plot (x, y, type = "l" , col = "blue" , lwd = 2, main = "Sine Function" ,
xlab = "x" , ylab = "y" )
ticks <- pretty (x, n = 10)
axis (1, at = ticks, labels = round (ticks, 2))
|
output :
Last Updated :
11 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...