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.
Concatenating data frames in R versus SAS
4 messages · ramoss, David Winsemius, Nordlund, Dan (DSHS/RDA)
On Aug 23, 2012, at 1:55 PM, ramoss wrote:
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
This would be the point at which I would want to know the results of: str(agency) str(prop)
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
Code... we want code. .... and data.
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 Alameda, CA, USA
-----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
I used summary <-rbind.fill(agency,prop) & it worked like a charm. Thanks everyone. -- View this message in context: http://r.789695.n4.nabble.com/Concatenating-data-frames-in-R-versus-SAS-tp4641138p4641219.html Sent from the R help mailing list archive at Nabble.com.