[R] Combinig two data frames
Petr Pikal
petr.pikal at precheza.cz
Mon Jun 12 11:51:48 CEST 2006
Hi
I would recommend to use list instead
how do you know that the result shall not be
A B
1 NA
3 5
4 6
5 3
2 5
> A<-1:5
> B<-4:7
> L<-list(A,B)
> L
[[1]]
[1] 1 2 3 4 5
[[2]]
[1] 4 5 6 7
If you insist on data frame you has to tell the program which cells
are to be empty or if you have common column(s) you can use merge
> CC
state psu weight
1 A. P. Urban 0
2 Mah. Rural 0
3 W.B. Rural 0
4 Ass. Rural 0
5 M. P. Urban 0
6 A. P. Urban 0
> CC1
state psu aaa
1 A. P. Urban 1.3
2 A. P. Rural 1.2
3 M. P. Urban 0.8
>
merge(CC,CC1, all=T)
state psu weight aaa
1 A. P. Rural NA 1.2
2 A. P. Urban 0 1.3
3 A. P. Urban 0 1.3
4 Ass. Rural 0 NA
5 M. P. Urban 0 0.8
6 Mah. Rural 0 NA
7 W.B. Rural 0 NA
HTH
Petr
On 12 Jun 2006 at 14:44, Arun Kumar Saha wrote:
Date sent: Mon, 12 Jun 2006 14:44:14 +0530
From: "Arun Kumar Saha" <arun.kumar.saha at gmail.com>
To: "r-help at stat.math.ethz.ch" <R-help at stat.math.ethz.ch>
Subject: [R] Combinig two data frames
> Dear all r-users,
>
> Suppose I have two data frame:
>
> A
> 1
> 3
> 4
> 5
> 2
>
> and
>
> B
> 5
> 6
> 3
> 5
>
> Now I want combine this two data frames without losing any value from
> either data frame. More precisely I want to see
>
> A B
> 1 5
> 3 6
> 4 3
> 5 5
> 2 NA
>
> I tried with cbind function but failed, as it only works when two data
> frames have equal number of rows. Can anyone suggest me any code that
> can be used for any data set?
>
> Thanks and regards
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list