> -----Original Message-----
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of ramoss
> Sent: Thursday, August 23, 2012 1:55 PM
> To: r-help@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


______________________________________________
R-help@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.

Reply via email to