> Is because the category is not unique, then merge are replicate the  
> values.


Yeah, ok.

But that is exactly my problem with the actual data set, I don't want  
"new" rows;

If I have;

x1
1       4
1       3
1       6
2       9
2       2


x2
1       -3
1       -7
2       -3
2       -2



I want this data.frame;

x1.x2
1       4       -3
1       3       -7
1       6       NA
2       9       -3
2       2       -2

or

x1.x2
1       4       -3
1       3       -7
2       9       -3
2       2       -2




It does not matter to me if the rows are merged like;

1       4       -3
1       3       -7

or

1       4       -7
1       3       -3




can I also do something like that with merge() ?



Am 18.06.2009 um 03:18 schrieb Henrique Dallazuanna:

> Is because the category is not unique, then merge are replicate the  
> values.
>
> Try this example:
>
> x <- data.frame(category=1:10, rnorm(10))
> y <- data.frame(category=3:12, rnorm(10))
>
> merge(x, y, by = "category")
> merge(x, y, by="category", all = T)
>
>
> On Wed, Jun 17, 2009 at 10:04 PM, Martin Batholdy <batho...@googlemail.com 
> > wrote:
> I have tried to replicate the example on the help page;
>
>
> x <- data.frame(category = sample(3, 10, r=TRUE), rnorm(10, 5, 2))
> y <- data.frame(category = sample(3, 10, r=TRUE), rnorm(10, 8, 2))
>
> merge(x, y, by = "category")
>
>
>
> When I do that, I get a data.frame with 28 rows instead of 10.
>
> What am I doing wrong?
>
>
>
> Am 18.06.2009 um 02:42 schrieb David Winsemius:
>
>
> Red the help page for merge:
>
> ?merge
>
>
> On Jun 17, 2009, at 8:33 PM, Martin Batholdy wrote:
>
> hi,
>
>
> I have two data.frames each with two columns;
>
>
> x1
>
> 1       4
> 1       3
> 1       6
> 2       9
> 2       2
> 2       5
> 3       6
> 3       7
> 3       4
>
>
> x2
>
> 1       -3
> 1       -7
> 2       -3
> 2       -2
> 2       -8
> 3       -1
> 3       -2
> 3       -1
>
> now I want to merge this data.frames to one data.frame.
>
> The problem is, that sometimes there is a different number of  
> elements per category.
> (like above x1 has 3 values for the value 1 in the first row, but x2  
> has only 2 values for the value 1 in the first row).
>
> Is there an easy way to merge this two data.frames by deleting the  
> rows that only one data.frame "has".
> In the example, that resulting data.frame would be the data.frame x1  
> and x2 except the row 3 of data.frame x1.
>
> thanks for any suggestions!
>
> ______________________________________________
> R-help@r-project.org 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.
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>
> ______________________________________________
> R-help@r-project.org 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.
>
>
>
> -- 
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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 via email to