rbind produces Error in match.names(clabs, names(xi))

user3614783 picture user3614783 · Jul 28, 2015 · Viewed 11.2k times · Source

A similar question was asked back in 2010. It got 12K views, but no solution. This is the post:

Merge multiple data frames - Error in match.names(clabs, names(xi)) : names do not match previous names

I downloaded identically formatted reports from Facebook business manager. But when I attempt to combine them using rbind(df1,df2) I get

Error in match.names(clabs, names(xi)) : names do not match previous names

By way of diagnostics, I compared

x<-names(df1) to y<-names(df2)

x and y were identical, and I also checked object.size(x) and object.size(y), and these were also identical.

The smartbind function in the gtools package seems to work, but I'd like to understand how to solve this in base R. This is 2 rows from each of two dataframes:

> dput(df1)
structure(list(Campaign.Name = c("Bad Kitty Drawn to Trouble", 
"Bad Kitty Drawn to Trouble"), Results = c(0L, 0L), performance_indicator = c("", 
""), Reach = c(17465L, 29848L), Cost.per.Result..USD. = c(0, 
0), Amount.Spent..USD. = c(10.48, 35.83), Ends = c("2014-02-03", 
"2014-02-03"), adgroup_id = c(NA, NA), Button.Clicks = c(0L, 
0L), Campaign.ID = c(6014996473560, 6014996473560), campaign_id = c(NA, 
NA), campaign_name = c(NA, NA), Clicks = c(41L, 229L), Cost.Per.All.Actions..USD. = c(0.80615384615385, 
0.3852688172043), Cost.Per.Unique.Click..USD. = c(0.262, 0.16435779816514
), CPC..Cost.Per.Click...USD. = c(0.25560975609756, 0.15646288209607
), CPM..Cost.Per.1.000.Impressions...USD. = c(0.34396744124984, 
0.61315992128005), Cost.Per.1.000.People.Reached..USD. = c(0.60005725737189, 
1.2004154382203), CTR..Click.Through.Rate. = c(0.13456741499278, 
0.39188842303414), Start.Date = c("2014-01-07", "2014-01-08"), 
    End.Date = c("2014-01-07", "2014-01-08"), Frequency = c(1.7445176066419, 
    1.9577526132404), Impressions = c(30468L, 58435L), Objective = c("NONE", 
    "NONE"), relevance_score.score = c(NA, NA), relevance_score.positive_feedback = c(NA, 
    NA), relevance_score.negative_feedback = c(NA, NA), Result.Rate..USD. = c(0, 
    0), Social.Clicks = c(0L, 4L), Social.Impressions = c(1239L, 
    5756L), Social.Reach = c(499L, 1749L), Amount.Spent.Today..USD. = c(0L, 
    0L), Total.Conversion.Value = c(0L, 0L), Actions = c(13L, 
    93L), People.Taking.Action = c(13L, 93L), Unique.Clicks = c(40L, 
    218L), Unique.Click.Through.Rate..uCTR. = c(0.22902948754652, 
    0.73036719378183), unique_social_clicks = c(0L, 4L), action_values.gift_sale = c(NA, 
    NA), actions.checkin = c(NA, NA), actions.receive_offer = c(NA, 
    NA), actions.follow = c(NA, NA), actions.games.plays = c(NA, 
    NA), actions.gift_sale = c(NA, NA), Page.Likes = c(13L, 91L
    ), Website.Clicks = c(NA_integer_, NA_integer_), Page.Mentions = c(NA_integer_, 
    NA_integer_), Page.Engagement = c(13L, 93L), Photo.Views = c(NA, 
    1L), Post.Shares = c(NA_integer_, NA_integer_), Post.Comments = c(NA_integer_, 
    NA_integer_), Post.Engagement = c(NA, 2L), Post.Likes = c(NA, 
    1L), actions.tab_view = c(NA, NA), actions.vote = c(NA, NA
    ), Cost.per.Check.In..USD. = c(NA, NA), Cost.per.Offer.Claim..USD. = c(NA, 
    NA), Cost.per.Question.Follow..USD. = c(NA, NA), Cost.per.Game.Play..USD. = c(NA, 
    NA), Cost.per.Gift.Sale..USD. = c(NA, NA), Cost.per.Page.Like..USD. = c(0.80615384615385, 
    0.39373626373626), Cost.per.Website.Click..USD. = c(NA_real_, 
    NA_real_), Cost.per.Page.Mention..USD. = c(NA_real_, NA_real_
    ), Cost.per.Page.Engagement..USD. = c(0.80615384615385, 0.3852688172043
    ), Cost.per.Photo.View..USD. = c(NA, 35.83), Cost.per.Post.Share..USD. = c(NA_real_, 
    NA_real_), Cost.per.Post.Comment..USD. = c(NA_real_, NA_real_
    ), Cost.per.Post.Engagement..USD. = c(NA, 17.915), Cost.per.Post.Like..USD. = c(NA, 
    35.83), Cost.per.Page.Tab.View..USD. = c(NA, NA), Cost.per.Question.Answer..USD. = c(NA, 
    NA), website_ctr.link_click = c(NA_real_, NA_real_), campaign_end = c(NA, 
    NA), campaign_start = c(NA, NA), Account = c("MCPG", "MCPG"
    )), .Names = c("Campaign.Name", "Results", "performance_indicator", 
"Reach", "Cost.per.Result..USD.", "Amount.Spent..USD.", "Ends", 
"adgroup_id", "Button.Clicks", "Campaign.ID", "campaign_id", 
"campaign_name", "Clicks", "Cost.Per.All.Actions..USD.", "Cost.Per.Unique.Click..USD.", 
"CPC..Cost.Per.Click...USD.", "CPM..Cost.Per.1.000.Impressions...USD.", 
"Cost.Per.1.000.People.Reached..USD.", "CTR..Click.Through.Rate.", 
"Start.Date", "End.Date", "Frequency", "Impressions", "Objective", 
"relevance_score.score", "relevance_score.positive_feedback", 
"relevance_score.negative_feedback", "Result.Rate..USD.", "Social.Clicks", 
"Social.Impressions", "Social.Reach", "Amount.Spent.Today..USD.", 
"Total.Conversion.Value", "Actions", "People.Taking.Action", 
"Unique.Clicks", "Unique.Click.Through.Rate..uCTR.", "unique_social_clicks", 
"action_values.gift_sale", "actions.checkin", "actions.receive_offer", 
"actions.follow", "actions.games.plays", "actions.gift_sale", 
"Page.Likes", "Website.Clicks", "Page.Mentions", "Page.Engagement", 
"Photo.Views", "Post.Shares", "Post.Comments", "Post.Engagement", 
"Post.Likes", "actions.tab_view", "actions.vote", "Cost.per.Check.In..USD.", 
"Cost.per.Offer.Claim..USD.", "Cost.per.Question.Follow..USD.", 
"Cost.per.Game.Play..USD.", "Cost.per.Gift.Sale..USD.", "Cost.per.Page.Like..USD.", 
"Cost.per.Website.Click..USD.", "Cost.per.Page.Mention..USD.", 
"Cost.per.Page.Engagement..USD.", "Cost.per.Photo.View..USD.", 
"Cost.per.Post.Share..USD.", "Cost.per.Post.Comment..USD.", "Cost.per.Post.Engagement..USD.", 
"Cost.per.Post.Like..USD.", "Cost.per.Page.Tab.View..USD.", "Cost.per.Question.Answer..USD.", 
"website_ctr.link_click", "campaign_end", "campaign_start", "Account"
), row.names = 1:2, class = "data.frame")
> dput(df2)
structure(list(Campaign.Name = c("Poison Pill", "Poison Pill"
), Results = c(0L, 0L), performance_indicator = c("", ""), Reach = c(3396L, 
4481L), Cost.per.Result..USD. = c(0, 0), Amount.Spent..USD. = c(15, 
15), Ends = c("2014-01-15", "2014-01-15"), adgroup_id = c(NA, 
NA), Button.Clicks = c(0L, 0L), Campaign.ID = c(6009475894829, 
6009475894829), campaign_id = c(NA, NA), campaign_name = c(NA, 
NA), Clicks = c(118L, 235L), Cost.Per.All.Actions..USD. = c(0.13157894736842, 
0.067873303167421), Cost.Per.Unique.Click..USD. = c(0.13761467889908, 
0.070754716981132), CPC..Cost.Per.Click...USD. = c(0.1271186440678, 
0.063829787234043), CPM..Cost.Per.1.000.Impressions...USD. = c(4.4117647058824, 
3.3452274754683), Cost.Per.1.000.People.Reached..USD. = c(4.416961130742, 
3.3474670832403), CTR..Click.Through.Rate. = c(3.4705882352941, 
5.2408563782337), Start.Date = c("2014-01-03", "2014-01-04"), 
    End.Date = c("2014-01-03", "2014-01-04"), Frequency = c(1.0011778563015, 
    1.0006694934166), Impressions = c(3400L, 4484L), Objective = c("NONE", 
    "NONE"), relevance_score.score = c(NA, NA), relevance_score.positive_feedback = c(NA, 
    NA), relevance_score.negative_feedback = c(NA, NA), Result.Rate..USD. = c(0, 
    0), Social.Clicks = c(11L, 22L), Social.Impressions = c(521L, 
    734L), Social.Reach = c(521L, 734L), Amount.Spent.Today..USD. = c(0, 
    0), Total.Conversion.Value = c(0L, 0L), Actions = c(114L, 
    221L), People.Taking.Action = c(114L, 217L), Unique.Clicks = c(109L, 
    212L), Unique.Click.Through.Rate..uCTR. = c(3.2096584216726, 
    4.7310868109797), unique_social_clicks = c(11L, 20L), action_values.gift_sale = c(NA, 
    NA), actions.checkin = c(NA, NA), actions.receive_offer = c(NA, 
    NA), actions.follow = c(NA, NA), actions.games.plays = c(NA, 
    NA), actions.gift_sale = c(NA, NA), Page.Likes = c(3L, NA
    ), Website.Clicks = c(111L, 221L), actions.mention = c(NA, 
    NA), Page.Engagement = c(114L, 221L), Photo.Views = c(NA_integer_, 
    NA_integer_), Post.Shares = c(NA_integer_, NA_integer_), 
    Post.Comments = c(NA_integer_, NA_integer_), Post.Engagement = c(111L, 
    221L), Post.Likes = c(NA_integer_, NA_integer_), actions.tab_view = c(NA, 
    NA), actions.vote = c(NA, NA), Cost.per.Check.In..USD. = c(NA, 
    NA), Cost.per.Offer.Claim..USD. = c(NA, NA), Cost.per.Question.Follow..USD. = c(NA, 
    NA), Cost.per.Game.Play..USD. = c(NA, NA), Cost.per.Gift.Sale..USD. = c(NA, 
    NA), Cost.per.Page.Like..USD. = c(5, NA), Cost.per.Website.Click..USD. = c(0.13513513513514, 
    0.067873303167421), Cost.per.Page.Mention..USD. = c(NA, NA
    ), Cost.per.Page.Engagement..USD. = c(0.13157894736842, 0.067873303167421
    ), Cost.per.Photo.View..USD. = c(NA_real_, NA_real_), Cost.per.Post.Share..USD. = c(NA_real_, 
    NA_real_), Cost.per.Post.Comment..USD. = c(NA_real_, NA_real_
    ), Cost.per.Post.Engagement..USD. = c(0.13513513513514, 0.067873303167421
    ), Cost.per.Post.Like..USD. = c(NA_real_, NA_real_), Cost.per.Page.Tab.View..USD. = c(NA, 
    NA), Cost.per.Question.Answer..USD. = c(NA, NA), website_ctr.link_click = c(3.2647058823529, 
    4.92863514719), campaign_end = c(NA, NA), campaign_start = c(NA, 
    NA), Account = c("TF", "TF")), .Names = c("Campaign.Name", 
"Results", "performance_indicator", "Reach", "Cost.per.Result..USD.", 
"Amount.Spent..USD.", "Ends", "adgroup_id", "Button.Clicks", 
"Campaign.ID", "campaign_id", "campaign_name", "Clicks", "Cost.Per.All.Actions..USD.", 
"Cost.Per.Unique.Click..USD.", "CPC..Cost.Per.Click...USD.", 
"CPM..Cost.Per.1.000.Impressions...USD.", "Cost.Per.1.000.People.Reached..USD.", 
"CTR..Click.Through.Rate.", "Start.Date", "End.Date", "Frequency", 
"Impressions", "Objective", "relevance_score.score", "relevance_score.positive_feedback", 
"relevance_score.negative_feedback", "Result.Rate..USD.", "Social.Clicks", 
"Social.Impressions", "Social.Reach", "Amount.Spent.Today..USD.", 
"Total.Conversion.Value", "Actions", "People.Taking.Action", 
"Unique.Clicks", "Unique.Click.Through.Rate..uCTR.", "unique_social_clicks", 
"action_values.gift_sale", "actions.checkin", "actions.receive_offer", 
"actions.follow", "actions.games.plays", "actions.gift_sale", 
"Page.Likes", "Website.Clicks", "actions.mention", "Page.Engagement", 
"Photo.Views", "Post.Shares", "Post.Comments", "Post.Engagement", 
"Post.Likes", "actions.tab_view", "actions.vote", "Cost.per.Check.In..USD.", 
"Cost.per.Offer.Claim..USD.", "Cost.per.Question.Follow..USD.", 
"Cost.per.Game.Play..USD.", "Cost.per.Gift.Sale..USD.", "Cost.per.Page.Like..USD.", 
"Cost.per.Website.Click..USD.", "Cost.per.Page.Mention..USD.", 
"Cost.per.Page.Engagement..USD.", "Cost.per.Photo.View..USD.", 
"Cost.per.Post.Share..USD.", "Cost.per.Post.Comment..USD.", "Cost.per.Post.Engagement..USD.", 
"Cost.per.Post.Like..USD.", "Cost.per.Page.Tab.View..USD.", "Cost.per.Question.Answer..USD.", 
"website_ctr.link_click", "campaign_end", "campaign_start", "Account"
), row.names = 1:2, class = "data.frame")

Answer

User7598 picture User7598 · Jul 28, 2015

See names(df1)==names(df2). You'll find that the name of variable #47 differs between df1 and df2, which causes the error.

To fix this issue, the variable names must be the same. To resolve this issue, you can do:

names(df1)[47]=c("actions.mention") #change variable name
names(df1)==names(df2) #ensure names are the same
rbind(df1,df2) #rbind two data frames.