从R中的数据帧中删除异常值?
我正在尝试从数据中删除异常值。在我的例子中,异常值是在箱线图上绘制时远离其余数据的值。删除异常值后,我将把数据保存在新文件中,并运行一些预测模型以查看结果。它们与原始数据有多大的不同 我使用了一个,并采用它从我的数据中删除异常值。本教程使用boxplotting计算异常值 当我在有异常值的列上运行它时,它工作得很好。但当我为没有异常值的列运行它时,它会引发错误。如何删除此错误 以下是代码:从R中的数据帧中删除异常值?,r,outliers,R,Outliers,我正在尝试从数据中删除异常值。在我的例子中,异常值是在箱线图上绘制时远离其余数据的值。删除异常值后,我将把数据保存在新文件中,并运行一些预测模型以查看结果。它们与原始数据有多大的不同 我使用了一个,并采用它从我的数据中删除异常值。本教程使用boxplotting计算异常值 当我在有异常值的列上运行它时,它工作得很好。但当我为没有异常值的列运行它时,它会引发错误。如何删除此错误 以下是代码: outlier_rem <- Data_combined #data-frame with 25 v
outlier_rem <- Data_combined #data-frame with 25 var, few have outliers
#removing outliers from the column
outliers <- boxplot(outlier_rem$var1, plot=FALSE)$out
#print(outliers)
ol <- outlier_rem[-which(outlier_rem$var1 %in% outliers),]
dim(ol)
# [1] 0 25
boxplot(ol)
以下作品
# Sample data based on mtcars and one additional row
df <- rbind(mtcars[, 1:3], c(100, 6, 300))
# Identify outliers
outliers <- boxplot(df$mpg, plot = FALSE)$out
#[1] 33.9 100.0
# Remove outliers
df[!(df$mpg %in% outliers), ]
比较
which(mtcars$mpg %in% outliers)
#integer(0)
与
这里有一个详细阐述这一点的例子。下面的工作
# Sample data based on mtcars and one additional row
df <- rbind(mtcars[, 1:3], c(100, 6, 300))
# Identify outliers
outliers <- boxplot(df$mpg, plot = FALSE)$out
#[1] 33.9 100.0
# Remove outliers
df[!(df$mpg %in% outliers), ]
比较
which(mtcars$mpg %in% outliers)
#integer(0)
与
这里有一个详细说明这一点的例子。你能举个数据例子吗?为了尝试代码:)玩具数据也是完美的!:)好的,我在我提供的教程中用数据测试了它。我的数据太大了。请尝试使用mtcars$disp[which(mtcars$disp>420)]*2)获取异常值,使用mtcars$disp[which(mtcars$disp>420)]获取无异常值错误数据。您能举一个数据示例吗?为了尝试代码:)玩具数据也是完美的!:)好的,我在我提供的教程中用数据测试了它。我的数据太大了。对于异常值,请使用mtcars$disp[which(mtcars$disp>420)]*2)进行尝试,对于无异常值数据的错误,请使用mtcars$disp[which(mtcars$disp>420)]*2进行尝试