У меня есть эта функция для поиска выбросов.Это прекрасно работает, кроме случаев, когда я ошибаюсь.
В таком случае мне нужно вернуться к началу.
Функция отображает распределение для каждой переменной в фрейме данных и запрашивает ввод данных пользователем по индексам, связанным с выбросами.
Это раздел функции.Он встроен в цикл 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 (), описанная здесь .
Есть ли способ сохранить любые входные данные ввектор, а затем распечатать их в конце функции?
В частности, напечатайте их, когда функция успешно завершится или если она прервана по пути.