[R] Merging yields "Error: unexpected input ..."

Daniel Malter daniel at umd.edu
Fri Jun 17 08:49:52 CEST 2011


Note what are supposed to be quotation marks around "ID" in your post are  "a
circumflex" instead. Maybe the problem is that the quotation marks that are
supposed to be around ID are not recognized by your R version. May you do
not use the proper font encoding. Use straight quotation marks or
apostrophes as you do in the read.table command in your code. Otherwise I
see not problem with your code, assuming the "ID" variable exists in both
datasets. Get back if the problem persists.

x<-data.frame(rnorm(10),letters[1:10])
names(x)=c('value','id')
y<-data.frame(1:10,letters[1:10])
names(y)=c('number','id')

merge(x,y)
merge(x,y,by="id")

HTH,
Daniel




William Mabe-2 wrote:
> 
> I am new to R and am having difficulty merging 2 data sets, both of which
> have the same 30 variables and about 2,000 records. I've looked high and
> low—Paul Johnson's help page, through some of the 5,420 (yikes!) results
> for “merge” on the R list archives, and google searches—and I'm
> getting nowhere, so I thought I'd ask. 
> 
> 
> 
> 
> When I try to merge by the ID variable: 
> 
> 
> 
> 
>> newdata <- merge(olddata_a, olddata_b, by = “ID”) 
> 
> 
> 
> 
> … I get the following error: 
> 
> 
> 
> 
> Error: unexpected input in "newdata <- merge(olddata_a, olddata_b, by =
> ‚" 
> 
> 
> 
> 
> Is this error symptomatic of anything in particular? When I searched, I
> didn' find any examples of this error associated with a merge. 
> 
> 
> 
> 
> I've also tried: 
> 
> 
> 
> 
>> newdata <- merge(olddata_a, olddata_b, all = TRUE) 
> 
> 
> 
> 
> ... which doesn't give me an error, but the “merge” just stacks the 2
> datasets on top of one another. (I have manually checked to make sure that
> there are common ID numbers in both datasets and there are.) I assume that
> I'm getting this stacked data because by not specifying a by variable, R
> is trying to match on all variables in the datasets and there are no exaxt
> matches across all the variables? 
> 
> 
> 
> 
> I've also tried to strip any white space that may be causing problems in
> the file. (Not sure if this is a good or bad idea.) 
> 
> 
> 
> 
>> newdata <- read.table("olddata.csv", header = TRUE, strip.white = TRUE,
>> sep=",") 
> 
> 
> 
> 
> I'd be really grateful for any help I could get. 
> 
> 
> 
> 
> Thank you. 
> 
> 
> 
> 
> Bill 
> -- 
> William F. Mabe, PhD 
> Director of Research and Evaluation 
> Faculty Fellow 
> John J. Heldrich Center for Workforce Development 
> 30 Livingston Ave., Office# 210 
> New Brunswick, NJ 08901 
> p: (732)932-4100 x6210 
> f: (732)932-3454 
> 
> 	[[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.
> 

--
View this message in context: http://r.789695.n4.nabble.com/Merging-yields-Error-unexpected-input-tp3604352p3604713.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list