在 R 编程中,抖动意味着向数字向量对象添加少量随机噪声。在本文中,我们将学习使用 jitter() 函数并创建一个图表来可视化它们。
用法: jitter(x, factor)
参数:
x:表示数值向量
factor:表示因子规范的数值
范例1:
# Define numeric vectors
x <- round(runif(1000, 1, 10))
y <- x + rnorm(1000, mean = 0, sd = 5)
# output to be present as PNG file
png(file="withoutJitter.png")
# Plotting without jitter function
plot(x, y, xlim = c(0, 11),
main = "Without Jitter Function")
# saving the file
dev.off()
x_j <- jitter(x)
# output to be present as PNG file
png(file="withJitter.png")
# Plotting with jitter function
plot(x_j, y, xlim = c(0, 11),
main = "With Jitter Function")
# saving the file
dev.off()
输出:
范例2:因子值大
# Define numeric vectors
x <- round(runif(1000, 1, 10))
y <- x + rnorm(1000, mean = 0, sd = 5)
# output to be present as PNG file
png(file="withoutJitterFactor.png")
# Plotting without jitter function
plot(x, y, xlim = c(0, 11),
main = "Without Jitter Function")
# saving the file
dev.off()
x_j <- jitter(x, factor = 2)
# output to be present as PNG file
png(file="withJitterFactor.png")
# Plotting with jitter function
plot(x_j, y, xlim = c(0, 11),
main = "With Jitter Function and Large Factor")
# saving the file
dev.off()
输出:
相关用法
- R语言 is.numeric()用法及代码示例
- R语言 which.min()用法及代码示例
- R语言 which.max()用法及代码示例
- R语言 sign()用法及代码示例
- R语言 as.vector()用法及代码示例
- R语言 is.vector()用法及代码示例
- R语言 append()用法及代码示例
- R语言 between()用法及代码示例
- R语言 cumprod()用法及代码示例
- R语言 cumsum()用法及代码示例
- R语言 atanh()用法及代码示例
- R语言 asinh()用法及代码示例
- R语言 acosh()用法及代码示例
- R语言 data.matrix()用法及代码示例
- R语言 as.character()用法及代码示例
- R语言 axis()用法及代码示例
注:本文由纯净天空筛选整理自utkarsh_kumar大神的英文原创作品 Adding Noise to a Numeric Vector in R Programming – jitter() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。