Message-ID: <F7E6D18CC2877149AB5296CE54EA276602547C46@WAXMXOLYMB002.WAX.wa.lcl>
Date: 2012-08-23T23:38:08Z
From: Nordlund, Dan (DSHS/RDA)
Subject: Concatenating data frames in R versus SAS
In-Reply-To: <1345755323514-4641138.post@n4.nabble.com>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of ramoss
> Sent: Thursday, August 23, 2012 1:55 PM
> To: r-help at r-project.org
> Subject: [R] Concatenating data frames in R versus SAS
>
> I am trying to concatenate 2 datasets that don't have exactly the same
> column.
> In SAS I did: data summary;
> set agency prop;
> run;
> No problem
> in R I get error message
> summary <-rbind(agency,prop)
> Error in match.names(clabs, names(xi)) :
> names do not match previous names
>
> But when I use rbin.fill, that overwrites the second file w/ first one.
> Is there a way to replicate the sas process in R?
>
> Thanks in advance
>
>
There may be a more R-ish way to do this, but here is a function to get you started.
SASrbind <- function(x, y) {
x[,setdiff(names(y),names(x))] <- NA
y[,setdiff(names(x),names(y))] <- NA
rbind(x,y)
}
wanted <- SASrbind(agency,prop)
Hope this is helpful,
Dan
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204