s-news
[Top] [All Lists]

Re: Combine dataframes different columns

To: "Bert Jacobs" <b.jacobs@pandora.be>
Subject: Re: Combine dataframes different columns
From: "Dimitris Rizopoulos" <dimitris.rizopoulos@med.kuleuven.be>
Date: Fri, 7 Oct 2005 13:35:44 +0200
Cc: <s-news@lists.biostat.wustl.edu>
References: <20051007105654.46A443811C@hoboe1bl1.telenet-ops.be>
you could try something like this:

a <- data.frame(rbind(1:10))
names(a) <- LETTERS[1:10]

b <- data.frame(cbind(1, 2, 2, 1, 1))
names(b) <- c("A", "D", "E", "I", "J")

################

dat <- merge(b, a, all = TRUE)[names(a)]
dat[is.na(dat)] <- 0
dat


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
    http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- From: "Bert Jacobs" <b.jacobs@pandora.be>
To: <s-news@lists.biostat.wustl.edu>
Sent: Friday, October 07, 2005 12:56 PM
Subject: [S] Combine dataframes different columns



Using S-Plus 6.2 for Windows XP

Hello,
I could use same help on merging two datasets

Dataframe 1 has as structure

    A B C D E F G H I J  (= column names)
Row 1     1 2 3 4 5 6 7 8 9 10

Dataframe 2 has as structure

    A D E I J  (= column names)
Row 1     1 2 2 1 1

And I'd like to become the following dataframe

    A B C D E F G H I J  (= column names)
Row 1     1 2 3 4 5 6 7 8 9 10
Row 2     1 0 0 2 2 0 0 0 1 1

What's the easiest way to do this? Any thoughts are welcome.

Kind regards,
Bert

--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm


<Prev in Thread] Current Thread [Next in Thread>