[R] Combining columns from two dataframes

David Winsemius dwinsemius at comcast.net
Wed Mar 18 04:40:10 CET 2009


What about just:

data.frame(z=c(a$a, b$c))

?
--  
David Winsemius
On Mar 17, 2009, at 10:44 PM, Steven McKinney wrote:

> Not sure how well this gets at what you want,
> but it seems close (if not kludgy!)
>
>> c <- data.frame(t(cbind(t(a), t(b))), stringsAsFactors = FALSE)[,  
>> 1, drop = FALSE]
>> c
>           a
> 1 2008-07-27
> 2 2008-10-01
> 3 2008-08-15
> 4 2008-08-14
> 5 2008-08-14
> 6 2008-09-20
> 7 2008-07-27
> 8 2008-10-01
>> c$a <- as.Date(c$a)
>> c
>           a
> 1 2008-07-27
> 2 2008-10-01
> 3 2008-08-15
> 4 2008-08-14
> 5 2008-08-14
> 6 2008-09-20
> 7 2008-07-27
> 8 2008-10-01
>> lapply(c, class)
> $a
> [1] "Date"
>
>>
>
>
> Steven McKinney, Ph.D.
>
> Statistician
> Molecular Oncology and Breast Cancer Program
> British Columbia Cancer Research Centre
>
> email: smckinney +at+ bccrc +dot+ ca
>
> tel: 604-675-8000 x7561
>
> BCCRC
> Molecular Oncology
> 675 West 10th Ave, Floor 4
> Vancouver B.C.
> V5Z 1L3
> Canada
>
>
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org on behalf of Andrew McFadden
> Sent: Tue 3/17/2009 2:55 PM
> To: r-help at r-project.org
> Subject: [R] Combining columns from two dataframes
>
> I all
>
> I am trying to combine columns from two dataframes to make a  
> completely
> new dataframe consisting of one column of dates (ie a combination of
> dates from the two dataframes).
>
>> From the following dataframes
>
>      a b
> 1 2008-07-27 1
> 2 2008-10-01 2
> 3 2008-08-15 3
> 4 2008-08-14 4
> 5 2008-08-14 5
> 6 2008-09-20 6
>
>           c d
> 1 2008-07-27 1
> 2 2008-10-01 2
>
> I would like to get:
>
>      z
> 2008-07-27
> 2008-10-01
> 2008-08-15
> 2008-08-14
> 2008-08-14
> 2008-09-20
> 2008-07-27
> 2008-10-01
>
> a<-
> data 
> .frame(as.Date(c("2008-07-27","2008-10-01","2008-08-15","2008-08-14"
> ,
> "2008-08-14","2008-09-20"), format = "%Y-%m-%d"),c(1:6))
> names(a)=c("a","b")
> a
> b<- data.frame(as.Date(c("2008-07-27","2008-10-01"), format =
> "%Y-%m-%d"),c(1:2))
> names(b)=c("c","d")
> a;b
>
> I have tried:
>
> append(a,b)
> combine(a,b)
> rbind(a,b)
>
> I would appreciate your help.
>
> Kind regards
>
> andy
>
> Andrew McFadden MVS BVSc
> Incursion Investigator
> Investigation & Diagnostic Centres - Wallaceville Biosecurity New
> Zealand Ministry of Agriculture and Forestry
>
> Phone 04 894 5600 Fax 04 894 4973 Mobile 029 894 5611 Postal address:
> Investigation and Diagnostic Centre- Wallaceville Box 40742 Ward St
> Upper Hutt
>
>
> ########################################################################
> This email message and any attachment(s) is intended solely for the
> addressee(s) named above. The information it contains is confidential
> and may be legally privileged.  Unauthorised use of the message, or  
> the
> information it contains, may be unlawful. If you have received this
> message by mistake please call the sender immediately on 64 4 8940100
> or notify us by return email and erase the original message and
> attachments. Thank you.
>
> The Ministry of Agriculture and Forestry accepts no responsibility for
> changes made to this email or to any attachments after transmission  
> from
> the office.
> ########################################################################
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
> ______________________________________________
> R-help at 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




More information about the R-help mailing list