Problems with Merging: 'by' must specify a uniquely valid column

SJSU2013 picture SJSU2013 · Nov 25, 2013 · Viewed 12.9k times · Source

I am having a problem mergin my datasets together. I get the above error message after I run the last line of code. However, both data sets have the same column name.

The head of avgRev2 is:

  avgRev         restaurantType
 1       33                 Afghan
 2       22                African
 3 56.84211         American (New)
 4 28.69203 American (Traditional)
 5        7              Argentine
 6 51.40909   Arts & Entertainment

The last two rows in expandedDataframe are:

isRestaurant restaurantType
X5          TRUE         Bagels
X10         TRUE     Sandwiches
X12         TRUE        Mexican
X14         TRUE          Pizza
X18         TRUE        Burgers
X23         TRUE        Buffets

I wrote the below code but it won't let me merge the data. I get the error :

Error in fix.by(by.x, x) : 'by' must specify a uniquely valid column

avgRev <- tapply(expandedDataFrame$review_count,expandedDataFrame$restaurantType,mean,simplify=FALSE)

avgRev2 <- as.data.frame(avgRev,)
avgRev2$category<-row.names(avgRev2)
row.names(avgRev2)=NULL

avgRev2 <- rename(avgRev2, c(category="restaurantType"))

expandedDataFrame2<- merge(expandedDataFrame, avgRev2, by="restuarantType")

Answer