-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtratamiento_outliers.R
60 lines (48 loc) · 1.76 KB
/
tratamiento_outliers.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
library(outliers)
outliers_prueba<-ajuste_RPM_Resistencia(df)
RPM_outliers<-sapply(outliers_prueba, "[",,1)
Resistencia_outliers<-sapply(outliers_prueba, "[",,2)
Resistencia_outliers<-sapply(Resistencia_outliers, function(x) as.numeric(as.character(x)))
chisq_outlier<-t(sapply(RPM_outliers, chisq.out.test))
alternative_outlier<- chisq_outlier[,2]
alternative_outlier<-str_extract_all(alternative_outlier,"\\d+")
make_outlier<- function(x){
return( paste(as.numeric(x[1]),as.numeric(x[2]), sep = "."))
}
alternative_outlier<- sapply(alternative_outlier,make_outlier)
Eliminar_outlier<- function(lista_rpms, vector_outliers){
difff<- abs(lista_rpms[length(lista_rpms)]-as.numeric(vector_outliers))
if(difff< 1){
ret<-lista_rpms[-length(lista_rpms)]
}else{ret<- lista_rpms}
return(ret)
}
RPM_sin_outliers<- lapply(RPM_outliers, Eliminar_outlier, vector_outliers=alternative_outlier)
tabla_sin_outliers<- function(resistencia,rpms){
if(length(resistencia)==length(rpms)){
tabla<-cbind(rpms,resistencia)
}else{
tabla<- cbind(rpms, resistencia[-length(resistencia)])
}
return(tabla)
}
tablas_sin_ot<-mapply(tabla_sin_outliers, rpms=RPM_sin_outliers, resistencia=Resistencia_outliers)
eliminar_decreasing<-function(validacion){
indeeex<- vector()
rr<- 1
for (i in 1:length(validacion[,1])) {
if(i==length(validacion[,1])){break}else{
if(validacion[i+1,1] < validacion[(i),1]){
indeeex[rr]<- as.numeric(i+1)
rr<-rr+1
}
}
}
if(length(indeeex)==0){
validacion<- validacion
}else{
validacion<-validacion[-indeeex,]
}
return(validacion)
}
tablas_sin_outliers_ni_decreasing<-lapply(tablas_sin_ot, eliminar_decreasing)