Hi,By default the merge function should take the intersection of column names (if this is understood from by = intersect(names(x), names(y)), but it takes all columns. How to specify the intersection of column names? ?Thanks Carol [[alternative HTML version deleted]]
1. Please read and follow the posting guide. 2. Reproducible example? (... at least I don't understand what you mean) 3. Plain text, not HTML. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Mon, Jun 1, 2015 at 6:46 AM, carol white via R-help <r-help at r-project.org> wrote:> Hi,By default the merge function should take the intersection of column > names (if this is understood from by = intersect(names(x), names(y)), but > it takes all columns. How to specify the intersection of column names? > Thanks > Carol > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]
As Burt says it is not exactly clear what you want but is something like this
what you are looking for?
dat1 <- data.frame(aa = c("a", "b", "c"), bb
= 1:3)
dat2 <- data.frame(xx = c("b", "c", "d"), yy
= 3:1)
merge(dat1, dat2, by.x = "aa", by.y = "xx")
For further reference here are some suggestions about asking questions on the
R-help list. In particular it is very helpful if data is supplied in dput()
form (See ?dput for details)
John Kane
Kingston ON Canada
> -----Original Message-----
> From: r-help at r-project.org
> Sent: Mon, 1 Jun 2015 13:46:15 +0000 (UTC)
> To: r-help at r-project.org
> Subject: [R] merge function
>
> Hi,By default the merge function should take the intersection of column
> names (if this is understood from by = intersect(names(x), names(y)), but
> it takes all columns. How to specify the intersection of column names?
> ?Thanks
> Carol
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
____________________________________________________________
Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.
On 01/06/2015 14:46, carol white via R-help wrote:> Hi,By default the merge function should take the intersection of column names(if this is understood from by = intersect(names(x), names(y)), Dear Carol The by parameter specifies which columns are used to merge by. Did you understand it to be which columns are retained in the result? Just a hunch, and if not then you need to give us a toy example. but it takes all columns. How to specify the intersection of column names?> Thanks > Carol > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >-- Michael http://www.dewey.myzen.co.uk/home.html
I understood that by would take the intersection of names(x) and names(y),
names(x) being the column names of x and names(y), column names of y.
if x has 5 col and the col names of x are col1, col2... col5 and y has 3 col and
their names are col1, col2, col3, I thought that the merged data set will have 3
col, namely col1, col2, col3 but all 5 col, i.e. col1, col2... col5 are taken if
nothing is specified for the by arg.
Cheers,
On Monday, June 1, 2015 4:32 PM, Michael Dewey <lists at
dewey.myzen.co.uk> wrote:
On 01/06/2015 14:46, carol white via R-help wrote:> Hi,By default the merge function should take the intersection of column
names
? (if this is understood from by = intersect(names(x), names(y)),
Dear Carol
The by parameter specifies which columns are used to merge by. Did you
understand it to be which columns are retained in the result?
Just a hunch, and if not then you need to give us a toy example.
? but it takes all columns. How to specify the intersection of column
names?>? Thanks
> Carol
>
> ??? [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
--
Michael
http://www.dewey.myzen.co.uk/home.html
[[alternative HTML version deleted]]