r - R:如何在我的函数中创建用户输入向量?
问题描述
我有这个查找异常值的功能。它工作得很好,除非我犯了错误。
在那种情况下,我需要一路回到起点。
该函数绘制数据框中每个变量的分布,并要求用户输入与异常值相关的索引。
这是函数的部分。它嵌入在 for 循环中。
#mark the extreme outliers, the rest are reasonable outliers
A <- colnames(df_out_id[i])
P <- readline(prompt="Would you like to see the full table of outliers? (enter to skip): ")
if(P == 0 | length(P) > 1){print("Reminder: the following questions identify outliers")}
if(P == "y" | P == "Y"){View(Outliers)}
W <- as.numeric(readline(prompt="Enter the index for first Extreme value on the lower limit (if none, enter 0): "))
Q <- as.numeric(readline(prompt="Enter the index for final Extreme value on the upper limit (if none, enter 0): "))
col <- df_out_id[i]
df_out_id[i] <- sapply(col[[1]], function(x){
if(Q>1 & x %in% Outliers$curr_column[1:Q]) return('Extreme')
if(W>1 & x %in% Outliers$curr_column[W:length(Outliers$curr_column)]) return('Extreme')
else if (x %in% Outliers$curr_column[Q+1:length(Outliers$curr_column)]) return('Reasonable')
else return('Non-Outlier')
})
}
#return a dataframe with outlier status, excluding the outlier ID columns
summary(df_out_id)
return(df_out_id[1:(length(names(df_out_id))-3)])
}
完整的函数是 GetOutliers(),在此处描述。
有没有办法将任何输入保存到向量中,然后在函数末尾打印它们?
具体来说,在函数成功完成或在此过程中中止的情况下打印它们。
解决方案
推荐阅读
- mysql - group by 和 counts 中的 Where 子句
- javascript - 制作一组图片的特殊旋转动画
- c# - 如何在 SqlCommand 之间使用 2?
- sql - SQL Server:使用 ROW_NUMBER 和 CASE 语句选择行
- python - 通过 **kwargs 获取变量,但抛出有关位置参数的错误
- c# - C# - 在按钮中实现枚举(创建新记录)
- java - 字段顺序的 Avro 模式 Java deepcopy 问题
- f# - 如何在 F# 中使用可变变量编写 += 操作
- css - 字体真棒图标上传到服务器时是正方形
- python - 一起替换多个正则表达式模式