This code works for me,
subset(merge(x1, x2, by = c("category", "id"), all = T), select=-id)
category rnorm.10..5..2. rnorm.10..8..2.
1 1 NA7.810377
2 16.4932819.002411
3 16.4932818.397378
4 12.757321
The word "merge" in the context of R suggests the use of the merge()
function, but I don't think that's the right tool for what you want.
The merge() function is for relational database type merges, which
for your data would have a many to many merge. Not good.
In terms of the R language, you'
thanks a lot!
That is really a big help.
I tried this code;
x1 <- data.frame(category = sample(3, 10, r=TRUE), rnorm(10, 5, 2))
x2 <- data.frame(category = sample(3, 10, r=TRUE), rnorm(10, 8, 2))
x1$id <- unlist(with(x1, tapply(x1[,2], x1[,1], seq)))
x2$id <- unlist(with(x2, tapply(x2[,
Yes, try this:
x1$id <- unlist(with(x1, tapply(x, x, seq)))
x2$id <- unlist(with(x2, tapply(x, x, seq)))
subset(merge(x1, x2, by = c("x", "id"), all = T), select = -id)
On Wed, Jun 17, 2009 at 10:24 PM, Martin Batholdy
wrote:
> Is because the category is not unique, then merge are replicate the
> 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
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
w
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
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
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.
9 matches
Mail list logo