Bueno, finalmente lo resolví así. Creé una nueva variable ORDEN2 con un ifelse que me señalase los duplicados de clase y luego selecciono los de menor ORDEN. Pierdo algunos registros de GRUPO porque solo tienen duplicados, pero esto estaba dentro de lo previsto.Gracias por la ayuda!
Datos%>% mutate(ORDEN2= ifelse(duplicated(CLASE),ORDEN==FALSE,ORDEN)) Datos2<-subset(Datos,!ORDEN2==FALSE)%>% group_by(GRUPO) %>% slice(which.min(ORDEN2)) Datos2 Datos2 grupo orden clase orden2 1 A 1 CLASE-01 1 2 B 7 CLASE-04 7 3 E 1 CLASE-06 1 4 F 7 CLASE-05 7 5 G 1 CLASE-07 1 El Miércoles 7 de marzo de 2018 13:51, Isidro Hidalgo Arellano <ihida...@jccm.es> escribió: #yiv2107649944 #yiv2107649944 -- _filtered #yiv2107649944 {font-family:Helvetica;panose-1:2 11 6 4 2 2 2 2 2 4;} _filtered #yiv2107649944 {panose-1:2 4 5 3 5 4 6 3 2 4;} _filtered #yiv2107649944 {font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;} _filtered #yiv2107649944 {panose-1:2 11 6 9 4 5 4 2 2 4;}#yiv2107649944 #yiv2107649944 p.yiv2107649944MsoNormal, #yiv2107649944 li.yiv2107649944MsoNormal, #yiv2107649944 div.yiv2107649944MsoNormal {margin:0cm;margin-bottom:.0001pt;font-size:12.0pt;}#yiv2107649944 a:link, #yiv2107649944 span.yiv2107649944MsoHyperlink {color:blue;text-decoration:underline;}#yiv2107649944 a:visited, #yiv2107649944 span.yiv2107649944MsoHyperlinkFollowed {color:purple;text-decoration:underline;}#yiv2107649944 pre {margin:0cm;margin-bottom:.0001pt;font-size:10.0pt;}#yiv2107649944 span.yiv2107649944HTMLconformatoprevioCar {}#yiv2107649944 span.yiv2107649944EstiloCorreo19 {color:#1F497D;}#yiv2107649944 span.yiv2107649944gghfmyibcpb {}#yiv2107649944 span.yiv2107649944gghfmyibcob {}#yiv2107649944 span.yiv2107649944EstiloCorreo22 {color:#1F497D;}#yiv2107649944 .yiv2107649944MsoChpDefault {font-size:10.0pt;} _filtered #yiv2107649944 {margin:70.85pt 3.0cm 70.85pt 3.0cm;}#yiv2107649944 div.yiv2107649944WordSection1 {}#yiv2107649944 Perdona. A ver ahora: > datos GRUPO ORDEN CLASE1 A 1 CLASE-012 A 2 CLASE-023 A 5 CLASE-034 B 1 CLASE-015 B 2 CLASE-026 B 5 CLASE-037 B 7 CLASE-048 C 2 CLASE-029 C 5 CLASE-0310 C 7 CLASE-0411 D 5 CLASE-0312 D 7 CLASE-0413 E 1 CLASE-0614 F 2 CLASE-0215 F 5 CLASE-0316 F 7 CLASE-0517 G 1 CLASE-07> clases = attr(table(datos$CLASE), "names")> grupos = attr(table(datos$GRUPO), "names")> datosFinal = datos[1,]> clases = clases[-1]> grupos = grupos[-1]> for (g in grupos){+ selec = datos[datos$GRUPO ==g & datos$CLASE %in% clases,]+ selec = selec[1,]+ clases = clases[clases != selec$CLASE]+ datosFinal = rbind(datosFinal, selec)+ }> datosFinal GRUPO ORDEN CLASE1 A 1 CLASE-015 B 2 CLASE-029 C 5 CLASE-0312 D 7 CLASE-0413 E 1 CLASE-0616 F 7 CLASE-0517 G 1 CLASE-07 Un saludo Isidro Hidalgo ArellanoObservatorio del Mercado de TrabajoConsejería de Economía, Empresas y Empleohttp://www.castillalamancha.es/ De: Isidro Hidalgo Arellano [mailto:ihida...@jccm.es] Enviado el: miércoles, 07 de marzo de 2018 13:00 Para: 'jose luis' <pepe...@yahoo.es>; 'r-help-es@r-project.org' <r-help-es@r-project.org> Asunto: RE: [R-es] Más filtrado de variables Una forma sería ésta: > datos GRUPO ORDEN CLASE1 A 1 CLASE-012 A 2 CLASE-023 A 5 CLASE-034 B 1 CLASE-015 B 2 CLASE-026 B 5 CLASE-037 B 7 CLASE-048 C 2 CLASE-029 C 5 CLASE-0310 C 7 CLASE-0411 D 5 CLASE-0312 D 7 CLASE-0413 E 1 CLASE-0614 F 2 CLASE-0215 F 5 CLASE-0316 F 7 CLASE-0517 G 1 CLASE-07> clases = attr(table(datos$CLASE), "names")> grupos = attr(table(datos$GRUPO), "names")> datosFinal = datos[1,]> clases = clases[-1]> grupos = grupos[-1]> for (g in grupos){+ selec = datos[datos$GRUPO ==g & datos$CLASE %in% clases,]+ selec = selec[1,]+ clases = clases[clases != selec$CLASE]+ datosFinal = rbind(datosFinal, selec)+ }> datosFinal GRUPO ORDEN CLASE1 A 1 CLASE-015 B 2 CLASE-029 C 5 CLASE-0312 D 7 CLASE-0413 E 1 CLASE-0616 F 7 CLASE-0517 G 1 CLASE-07 Básicamente es montar un cola con las clases para ir quitándole el valor que va saliendo en cada grupo. Un saludo Isidro Hidalgo ArellanoObservatorio del Mercado de TrabajoConsejería de Economía, Empresas y Empleohttp://www.castillalamancha.es/ De: R-help-es [mailto:r-help-es-boun...@r-project.org] En nombre de jose luis via R-help-es Enviado el: miércoles, 07 de marzo de 2018 12:01 Para: jose luis <pepe...@yahoo.es>; Lista R. <r-help-es@r-project.org> Asunto: Re: [R-es] Más filtrado de variables Adjunto txt por si no se ve bien, disculpas El Miércoles 7 de marzo de 2018 11:53, jose luis via R-help-es <r-help-es@r-project.org> escribió: Buenas. A ver si a alguien se le ocurre cómo hacer este filtrado. Quiero seleccionar para cada GRUPO el numero de ORDEN más pequeño (que podría ser con wich.min(ORDEN)), pero sin que se repita la CLASE, de modo que si la CLASE-01 salió en el primer GRUPO ya no salga más. GRUPO ORDEN CLASE A 1 CLASE-01 A 2 CLASE-02 A 5 CLASE-03 B 1 CLASE-01 B 2 CLASE-02 B 5 CLASE-03 B 7 CLASE-04 C 2 CLASE-02 C 5 CLASE-03 C 7 CLASE-04 D 5 CLASE-03 D 7 CLASE-04 E 1 CLASE-06 F 2 CLASE-02 F 5 CLASE-03 F 7 CLASE-05 G 1 CLASE-07 Tendría que quedarme tal que así: GRUPO ORDEN CLASE A 1 CLASE-01 B 2 CLASE-02 C 5 CLASE-03 D 7 CLASE-04 E 1 CLASE-06 F 7 CLASE-05 G 1 CLASE-07 Un saludo Jose Luis [[alternative HTML version deleted]] _______________________________________________ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es [[alternative HTML version deleted]] _______________________________________________ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es