[R-es] eliminar outliers en un tapply

Manuel Mendoza mmendoz@ @end|ng |rom |u|br|ghtm@||@org
Lun Dic 5 13:57:32 CET 2022


Gracias Francisco, Carlos me ayudó a resolver el problema, pero revisaré
también el tuyo, pues parece interesante.
Un saludo

El lun, 5 dic 2022 a las 12:09, Francisco Rodriguez Sanchez (<
f.rodriguez.sanc using gmail.com>) escribió:

> Buenos días Manuel
>
> Pues le he pedido a ChatGPT (https://openai.com/blog/chatgpt/)
> exactamente esto
>
> "Write R code to remove outliers from a numeric vector stratified by
> levels of a factor"
>
> y me ha devuelto literalmente esta solución que pego abajo (que a mí
> sinceramente no se me habría ocurrido)
>
> Estoy alucinando con el potencial de estas nuevas herramientas
>
> Saludos
>
>
> |# Generate a sample dataset with 30 data points set.seed(123) x <-
> rnorm(30, mean = 10, sd = 2) factor <- sample(c("A", "B", "C", "D",
> "E"), 30, replace = TRUE) # Create a boxplot of the numeric vector,
> stratified by the levels of the factor boxplot(x ~ factor)|
>
> |# Identify the outliers outliers <- boxplot(x ~ factor, plot =
> FALSE)$out # Subset the data to remove the outliers x_no_outliers <-
> subset(x, !x %in% outliers) # View the resulting vector x_no_outliers #>
> [1] 8.879049 9.539645 10.141017 10.258575 13.430130 10.921832 7.469878
> #> [8] 8.626294 9.108676 12.448164 10.719628 10.801543 10.221365
> 8.888318 #> [15] 13.573826 10.995701 6.066766 11.402712 9.054417
> 9.564050 7.947991 #> [22] 8.542218 8.749921 6.626613 11.675574 10.306746
> 7.723726 12.507630|
>
> ^Created on 2022-12-05 with reprex v2.0.2 <https://reprex.tidyverse.org>
>
>
>
> ^
>
> On 3/12/22 9:14, Manuel Mendoza wrote:
> > Buenos días, utilizo:
> >
> > max <- tapply (Data$varnum, Data$varcat, max)
> >
> > para obtener el máximo de varnum en cada una de las categorías de varcat
> >
> > ¿cómo podría obtener los máximos, pero sin los outliers (Q75 + 1.5*IQR)?
> >
> > Es fácil quitar los outliers superiores de varnum, pero no es eso lo que
> > necesito quitar, sino los outliers dentro ya de cada categoría de varcat.
> >
> > Gracias, como siempre,
> > Manuel
> >
> >       [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-help-es mailing list
> > R-help-es using r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
>
> --
> Dr Francisco Rodríguez-Sánchez
> https://frodriguezsanchez.net
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-help-es mailing list
> R-help-es using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

	[[alternative HTML version deleted]]



Más información sobre la lista de distribución R-help-es