[R-es] Transponer data frame.

juan manuel dias ju@m@di@@ @ending from gm@il@com
Vie Oct 12 00:40:10 CEST 2018


muchas gracias!

El jue., 11 oct. 2018 a las 16:03, José Trujillo Carmona (<trujillo using unex.es>)
escribió:

> Mediante unstack y reordenando columnas con <- [, ...]
>
> > NV<-c(1240,1240,1240,1240,1241,1241,1241,1241)
>
> >
> Nc<-c("Argentina","Uruguaya","Paraguaya","Brasilera","Argentina","Uruguaya","Paraguaya","Brasilera")
>
> > Pax<-c(2341,4432,67000,1234,7344,543000,3000,234000)
>
> > (DDD<-data.frame(NV,Nc,Pax))
>     NV        Nc    Pax
> 1 1240 Argentina   2341
> 2 1240  Uruguaya   4432
> 3 1240 Paraguaya  67000
> 4 1240 Brasilera   1234
> 5 1241 Argentina   7344
> 6 1241  Uruguaya 543000
> 7 1241 Paraguaya   3000
> 8 1241 Brasilera 234000
>
> > (UUU<-unstack(DDD[,2:3],DDD$Pax~DDD$Nc))
>   Argentina Brasilera Paraguaya Uruguaya
> 1      2341      1234     67000     4432
> 2      7344    234000      3000   543000
>
> > UUU$NV<-seq(1240,1241)
>
> > (FFF<-UUU[,c(5,seq(1,4)))
>
> > (FFF<-UUU[,c(5,seq(1,4))])
>     NV Argentina Brasilera Paraguaya Uruguaya
> 1 1240      2341      1234     67000     4432
> 2 1241      7344    234000      3000   543000
>
> Saludos
> El 11/10/18 a las 17:32, juan manuel dias escribió:
>
> Hola,
> Tengo la siguiente base de datos
>
> Numero de vuelo Nacionalidad Pax
> 1240 Argentina 2341
> 1240 Uruguaya 4432
> 1240 Paraguaya 67000
> 1240 Brasilera 1234
> 1241 Argentina 7344
> 1241 Uruguaya 543000
> 1241 Paraguaya 3000
> 1241 Brasilera 234000
> y quiero que quede del siguiente modo:
>
> Numero de vuelo Nacionalidad_argentina Nacionalidad_uruguaya
> Nacionalidad_paraguaya Nacionalidad_brasilera
> 1240 2341 4432 67000 1234
> 1241 7344 543000 3000 234000
>
>  intenté con *vuelos_f<-t(vuelos) *pero no logro lo que quiero, queda así:
>
> [image: image.png]
>
> Muchas gracias! Saludos, Juan.
>
> _______________________________________________
> R-help-es mailing listR-help-es using r-project.orghttps://stat.ethz.ch/mailman/listinfo/r-help-es
>
> _______________________________________________
> R-help-es mailing list
> R-help-es using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20181011/59868671/attachment-0001.html>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 6075 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20181011/59868671/attachment-0002.png>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 6075 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20181011/59868671/attachment-0003.png>


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