titeuf
titeuf

Reputation: 163

left_join says column is not present even though it is present

I would like to join two data frames with two different variables tp join. There is an error which says it cannotfind the variable in the second dataframe. But when I run the function colnames(), the column name shows up. Why is this the case?

df_new <- left_join(master_settlement_current_month, master_settlement, by = c("D.settlecounty", "NAMECOUNTY"))

Error: Join columns must be present in data.
x Problem with `NAMECOUNTY`.
Run `rlang::last_error()` to see where the error occurred.

colnames(master_settlement_current_month)[1:5]
[1] "month"             "D.info_state"      "D.info_county"     "D.info_settlement" "D.settlecounty" 

  
colnames(master_settlement)
 [1] "NAME"            "NAMEJOIN"        "NAMECOUNTY"      "COUNTYJOIN"      "DATE"            "DATA_SOURC"      "IMG_VERIFD"     
 [8] "X"               "Y"               "kobo_label"      "X.3"             "X.2"             "X.1"             "INDEX"          
[15] "P_CODE"          "aok_sett_id"     "name_county_low" "ALT_NAME1"       "ALT_NAME2"       "ALT_NAME3"       "ALT_NAME4"      
[22] "FUNC_CLASS"      "CONF_SCORE"      "SRC_VERIFD"      "num_dup"         "check_coord_v38"

Upvotes: 4

Views: 6568

Answers (1)

tonybot
tonybot

Reputation: 655

I think your syntax in the by = statement may be a little off.

library(dplyr)

df_new <- left_join(master_settlement_current_month, master_settlement, by = c("D.settlecounty" = "NAMECOUNTY"))

Upvotes: 5

Related Questions