Skip to content

Concatenating data frames in R versus SAS

4 messages · ramoss, David Winsemius, Nordlund, Dan (DSHS/RDA)

#
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



--
View this message in context: http://r.789695.n4.nabble.com/Concatenating-data-frames-in-R-versus-SAS-tp4641138.html
Sent from the R help mailing list archive at Nabble.com.
#
On Aug 23, 2012, at 1:55 PM, ramoss wrote:

            
This would be the point at which I would want to know the results of:

str(agency)
str(prop)
Code... we want code.  .... and data.

  
    
#
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