merge 2 data.frames

classic Classic list List threaded Threaded
5 messages Options
Mat
Reply | Threaded
Open this post in threaded view
|

merge 2 data.frames

Mat
Hello together,

i have probably a easy question, but how can i sum 2 data.frames among each other.
I have 2 data.frames which look like this one:

        Cu.No.      place      level
1     123            London  A
2    111             Paris       B

        Cu.No.      place      level
1     333            Berlin      C
2    444             Madrid    A

and now i want this data in the same data.frame. like this one:

        Cu.No.      place      level
1     123            London  A
2    111             Paris       B
3     333            Berlin      C
4    444             Madrid    A

how can i do this.

Thanks.

Mat
Reply | Threaded
Open this post in threaded view
|

Re: merge 2 data.frames

Jim Harris
This post has NOT been accepted by the mailing list yet.
try this:

dfa <- read.table(text="        Cu.No.      place      level
1     123            London  A
2    111             Paris       B ", header=TRUE)

dfb <- read.table(text="        Cu.No.      place      level
1     333            Berlin      C
2    444             Madrid    A ", header=TRUE)

merge(dfa,y=dfb,all=TRUE)

Jim

Mat wrote
Hello together,

i have probably a easy question, but how can i sum 2 data.frames among each other.
I have 2 data.frames which look like this one:

        Cu.No.      place      level
1     123            London  A
2    111             Paris       B

        Cu.No.      place      level
1     333            Berlin      C
2    444             Madrid    A

and now i want this data in the same data.frame. like this one:

        Cu.No.      place      level
1     123            London  A
2    111             Paris       B
3     333            Berlin      C
4    444             Madrid    A

how can i do this.

Thanks.

Mat
Reply | Threaded
Open this post in threaded view
|

Re: merge 2 data.frames

arun kirshna
This post has NOT been accepted by the mailing list yet.
In reply to this post by Mat
Hi,
You can use:
df1 <- read.table(text="        Cu.No.      place      level
1     123            London  A
2    111             Paris       B ", sep="", header=TRUE,stringsAsFactors=FALSE)

df2 <- read.table(text="        Cu.No.      place      level
1     333            Berlin      C
2    444             Madrid    A ", sep="", header=TRUE,stringsAsFactors=FALSE)
 merge(df1,df2,all=TRUE,sort=FALSE)
 # Cu.No.  place level
#1    123 London     A
#2    111  Paris     B
#3    333 Berlin     C
#4    444 Madrid     A
library(plyr)
 join(df1,df2,type="full")
#  Cu.No.  place level
#1    123 London     A
#2    111  Paris     B
#3    333 Berlin     C
#4    444 Madrid     A
A.K.
Reply | Threaded
Open this post in threaded view
|

Re: merge 2 data.frames

Alice Xiong
In reply to this post by Mat
 x<-matrix(c(1,11,11,2,3,4),2,3)
y<-matrix(x(7,8,9,10,11,12),2,3)
if you want to merge them by row, then use:
rbind(x,y)
if you want to merge them by column, then use
cbind(x,y)

hope this can help you out*----

Alice Xiong

On Wed, Feb 6, 2013 at 8:55 AM, Mat <[hidden email]> wrote:

> Hello together,
>
> i have probably a easy question, but how can i sum 2 data.frames among each
> other.
> I have 2 data.frames which look like this one:
>
>         Cu.No.      place      level
> 1     123            London  A
> 2    111             Paris       B
>
>         Cu.No.      place      level
> 1     333            Berlin      C
> 2    444             Madrid    A
>
> and now i want this data in the same data.frame. like this one:
>
>         Cu.No.      place      level
> 1     123            London  A
> 2    111             Paris       B
> 3     333            Berlin      C
> 4    444             Madrid    A
>
> how can i do this.
>
> Thanks.
>
> Mat
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/merge-2-data-frames-tp4657702.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: merge 2 data.frames

Eik Vettorazzi-2
In reply to this post by Mat
Hi Mat,
just have a look at ?rbind

cheers.

Am 06.02.2013 15:55, schrieb Mat:

> Hello together,
>
> i have probably a easy question, but how can i sum 2 data.frames among each
> other.
> I have 2 data.frames which look like this one:
>
>         Cu.No.      place      level
> 1     123            London  A
> 2    111             Paris       B
>
>         Cu.No.      place      level
> 1     333            Berlin      C
> 2    444             Madrid    A
>
> and now i want this data in the same data.frame. like this one:
>
>         Cu.No.      place      level
> 1     123            London  A
> 2    111             Paris       B
> 3     333            Berlin      C
> 4    444             Madrid    A
>
> how can i do this.
>
> Thanks.
>
> Mat
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/merge-2-data-frames-tp4657702.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


--
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.