2010-11-10 10 views
17

Mi pregunta es cómo se pueden unir dos o más marcos de datos en el sistema R?unir dos o más marcos de datos en el sistema R

Por ejemplo:

Tengo dos tramas de datos:

primeros:

x y z 
1 3 2 4 
2 4 5 7 
3 5 6 8 

segundo:

x y z 
1 1 1 1 
2 4 5 7 

necesito esto:

x y z 
1 3 2 4 
2 4 5 7 
3 5 6 8 
4 1 1 1 
5 4 5 7 

I trató de usar añadir para cada vector, como este:

para (i en 1: longitud (primera)) {

mix[[i]]<-append(first[i], second[i])} 

f < -do.call (rbind, mezclar)

Pero no funcionó como lo necesitaba. No obtuve mi matriz, obtuve una estructura diferente.

+0

Preguntas relacionadas: http://stackoverflow.com/questions/2851327/r-converting-a-list-of-data-frames-into-one-data-frame, http://stackoverflow.com/questions/ 2209258/merge-several-data-frames-into-one-data-frame-with-a-loop, http://stackoverflow.com/questions/1299871/how-to-join-data-frames-in-r- inner-outer-left-right, http://stackoverflow.com/questions/2392915/recombining-a-list-of-data-frames-into-a-single-data-frame, ... –

Respuesta

24

Tiene la idea correcta usando rbind(), pero es mucho más simple. Si sus marcos de datos se llaman "primero" y "segundo":

f <- rbind(first, second) 

Y f es el nuevo marco de datos.

+0

Gracias) Eso es Funciona genial. – olga

Cuestiones relacionadas