indicate if value in one column matches value in another column same row

Hi there,

I am trying to indicate for each row, does the text in the third column match the text in the fourth column?

I am attaching a subset of the dataset here.

structure(list(from_county = c("1069", "1055", "1073", "1095", 
"1003", "1007", "1015", "1019", "1021", "1025", "1031", "1033", 
"1045", "1047", "1049", "1051", "1055", "1069", "1073", "1077", 
"1081", "1083", "1089", "1091", "1095", "1097", "1101", "1103", 
"1105", "1109", "1113", "1117", "1121", "1125", "1131", "1001", 
"1005", "1007", "1009", "1011", "1013", "1015", "1021", "1025", 
"1031", "1039", "1041", "1043", "1045", "1049", "1051", "1053", 
"1059", "1069", "1071", "1073", "1077", "1081", "1083", "1085", 
"1089", "1091", "1093", "1095", "1097", "1099", "1101", "1103", 
"1105", "1107", "1109", "1111", "1115", "1117", "1119", "1121", 
"1123", "1125", "1129", "1133", "1001", "1003", "1007", "1011", 
"1013", "1017", "1019", "1027", "1031", "1039", "1045", "1051", 
"1053", "1055", "1065", "1067", "1069", "1073", "1081", "1083"
), to_county = c("10001", "10003", "10003", "10005", "1001", 
"1001", "1001", "1001", "1001", "1001", "1001", "1001", "1001", 
"1001", "1001", "1001", "1001", "1001", "1001", "1001", "1001", 
"1001", "1001", "1001", "1001", "1001", "1001", "1001", "1001", 
"1001", "1001", "1001", "1001", "1001", "1001", "1003", "1003", 
"1003", "1003", "1003", "1003", "1003", "1003", "1003", "1003", 
"1003", "1003", "1003", "1003", "1003", "1003", "1003", "1003", 
"1003", "1003", "1003", "1003", "1003", "1003", "1003", "1003", 
"1003", "1003", "1003", "1003", "1003", "1003", "1003", "1003", 
"1003", "1003", "1003", "1003", "1003", "1003", "1003", "1003", 
"1003", "1003", "1003", "1005", "1005", "1005", "1005", "1005", 
"1005", "1005", "1005", "1005", "1005", "1005", "1005", "1005", 
"1005", "1005", "1005", "1005", "1005", "1005", "1005"), from_EA = structure(c(48L, 
76L, 19L, 76L, 112L, 19L, 19L, 11L, 19L, 112L, 48L, 76L, 48L, 
114L, 76L, 114L, 76L, 48L, 19L, 76L, 39L, 76L, 76L, 112L, 76L, 
112L, 114L, 76L, 114L, 114L, 39L, 19L, 19L, 19L, 112L, 114L, 
48L, 19L, 19L, 114L, 114L, 19L, 19L, 112L, 48L, 48L, 114L, 19L, 
48L, 76L, 114L, 112L, 76L, 48L, 76L, 19L, 76L, 39L, 76L, 114L, 
76L, 112L, 19L, 76L, 112L, 112L, 114L, 76L, 114L, 19L, 114L, 
11L, 19L, 19L, 79L, 19L, 114L, 19L, 112L, 19L, 114L, 112L, 19L, 
114L, 114L, 11L, 11L, 19L, 48L, 48L, 48L, 114L, 112L, 76L, 19L, 
48L, 48L, 19L, 39L, 76L), .Label = c("Aberdeen, SD ", "Abilene, TX ", 
"Albany-Schenectady-Amsterdam, NY ", "Albany, GA ", "Albuquerque, NM ", 
"Alpena, MI ", "Amarillo, TX ", "Anchorage, AK ", "Appleton-Oshkosh-Neenah, WI ", 
"Asheville-Brevard, NC ", "Atlanta-Sandy Springs-Gainesville, GA-AL ", 
"Augusta-Richmond County, GA-SC ", "Austin-Round Rock, TX ", 
"Bangor, ME ", "Baton Rouge-Pierre Part, LA ", "Beaumont-Port Arthur, TX ", 
"Bend-Prineville, OR ", "Billings, MT ", "Birmingham-Hoover-Cullman, AL ", 
"Bismarck, ND ", "Boise City-Nampa, ID ", "Boston-Worcester-Manchester, MA-NH ", 
"Buffalo-Niagara-Cattaraugus, NY ", "Burlington-South Burlington, VT ", 
"Cape Girardeau-Jackson, MO-IL ", "Casper, WY ", "Cedar Rapids, IA ", 
"Champaign-Urbana, IL ", "Charleston-North Charleston, SC ", 
"Charleston, WV ", "Charlotte-Gastonia-Salisbury, NC-SC ", "Chicago-Naperville-Michigan City, IL-IN-WI ", 
"Cincinnati-Middletown-Wilmington, OH-KY-IN ", "Clarksburg, WV+Morgantown, WV ", 
"Cleveland-Akron-Elyria, OH ", "Colorado Springs, CO ", "Columbia-Newberry, SC ", 
"Columbia, MO ", "Columbus-Auburn-Opelika, GA-AL ", "Columbus-Marion-Chillicothe, OH ", 
"Corpus Christi-Kingsville, TX ", "Dallas-Fort Worth, TX ", "Davenport-Moline-Rock Island, IA-IL ", 
"Dayton-Springfield-Greenville, OH ", "Denver-Aurora-Boulder, CO ", 
"Des Moines-Newton-Pella, IA ", "Detroit-Warren-Flint, MI ", 
"Dothan-Enterprise-Ozark, AL ", "Dover, DE ", "Duluth, MN-WI ", 
"El Paso, TX ", "Erie, PA ", "Eugene-Springfield, OR ", "Evansville, IN-KY ", 
"Fargo-Wahpeton, ND-MN ", "Farmington, NM ", "Fayetteville-Springdale-Rogers, AR-MO ", 
"Flagstaff, AZ ", "Fort Smith, AR-OK ", "Fort Wayne-Huntington-Auburn, IN ", 
"Fresno-Madera, CA ", "Gainesville, FL ", "Grand Forks, ND-MN ", 
"Grand Rapids-Muskegon-Holland, MI ", "Great Falls, MT ", "Greensboro-Winston-Salem-High Point, NC ", 
"Greenville-Spartanburg-Anderson, SC ", "Greenville, NC ", "Gulfport-Biloxi-Pascagoula, MS ", 
"Harrisburg-Carlisle-Lebanon, PA ", "Harrisonburg, VA ", "Hartford-West Hartford-Willimantic, CT ", 
"Helena, MT ", "Honolulu, HI ", "Houston-Baytown-Huntsville, TX ", 
"Huntsville-Decatur, AL ", "Idaho Falls-Blackfoot, ID ", "Indianapolis-Anderson-Columbus, IN ", 
"Jackson-Yazoo City, MS ", "Jacksonville, FL ", "Johnson City-Kingsport-Bristol (Tri-Cities), TN-VA ", 
"Jonesboro, AR ", "Joplin, MO ", "Kansas City-Overland Park-Kansas City, MO-KS ", 
"Kearney, NE ", "Kennewick-Richland-Pasco, WA ", "Killeen-Temple-Fort Hood, TX ", 
"Knoxville-Sevierville-La Follette, TN ", "La Crosse, WI-MN ", 
"Lafayette-Acadiana, LA ", "Lake Charles-Jennings, LA ", "Las Vegas-Paradise-Pahrump, NV ", 
"Lewiston, ID-WA ", "Lexington-Fayette-Frankfort-Richmond, KY ", 
"Lincoln, NE ", "Little Rock-North Little Rock-Pine Bluff, AR ", 
"Los Angeles-Long Beach-Riverside, CA ", "Louisville-Elizabethtown-Scottsburg, KY-IN ", 
"Lubbock-Levelland, TX ", "Macon-Warner Robins-Fort Valley, GA ", 
"Madison-Baraboo, WI ", "Marinette, WI-MI ", "Mason City, IA ", 
"McAllen-Edinburg-Pharr, TX ", "Memphis, TN-MS-AR ", "Miami-Fort Lauderdale-Miami Beach, FL ", 
"Midland-Odessa, TX ", "Milwaukee-Racine-Waukesha, WI ", "Minneapolis-St. Paul-St. Cloud, MN-WI ", 
"Minot, ND ", "Missoula, MT ", "Mobile-Daphne-Fairhope, AL ", 
"Monroe-Bastrop, LA ", "Montgomery-Alexander City, AL ", "Myrtle Beach-Conway-Georgetown, SC ", 
"Nashville-Davidson-Murfreesboro-Columbia, TN ", "New Orleans-Metairie-Bogalusa, LA ", 
"New York-Newark-Bridgeport, NY-NJ-CT-PA ", "Oklahoma City-Shawnee, OK ", 
"Omaha-Council Bluffs-Fremont, NE-IA ", "Orlando-The Villages, FL ", 
"Paducah, KY-IL ", "Panama City-Lynn Haven, FL ", "Pendleton-Hermiston, OR ", 
"Pensacola-Ferry Pass-Brent, FL ", "Peoria-Canton, IL ", "Philadelphia-Camden-Vineland, PA-NJ-DE-MD ", 
"Phoenix-Mesa-Scottsdale, AZ ", "Pittsburgh-New Castle, PA ", 
"Portland-Lewiston-South Portland, ME ", "Portland-Vancouver-Beaverton, OR-WA ", 
"Pueblo, CO ", "Raleigh-Durham-Cary, NC ", "Rapid City, SD ", 
"Redding, CA ", "Reno-Sparks, NV ", "Richmond, VA ", "Roanoke, VA ", 
"Rochester-Batavia-Seneca Falls, NY ", "Sacramento-Arden-Arcade-Truckee, CA-NV ", 
"Salina, KS ", "Salt Lake City-Ogden-Clearfield, UT ", "San Angelo, TX ", 
"San Antonio, TX ", "San Diego-Carlsbad-San Marcos, CA ", "San Jose-San Francisco-Oakland, CA ", 
"Santa Fe-Espanola, NM ", "Sarasota-Bradenton-Venice, FL ", "Savannah-Hinesville-Fort Stewart, GA ", 
"Scotts Bluff, NE ", "Scranton-Wilkes-Barre, PA ", "Seattle-Tacoma-Olympia, WA ", 
"Shreveport-Bossier City-Minden, LA ", "Sioux City-Vermillion, IA-NE-SD ", 
"Sioux Falls, SD ", "South Bend-Mishawaka, IN-MI ", "Spokane, WA ", 
"Springfield, IL ", "Springfield, MO ", "St. Louis-St. Charles-Farmington, MO-IL ", 
"State College, PA ", "Syracuse-Auburn, NY ", "Tallahassee, FL ", 
"Tampa-St. Petersburg-Clearwater, FL ", "Texarkana, TX-Texarkana, AR ", 
"Toledo-Fremont, OH ", "Topeka, KS ", "Traverse City, MI ", "Tucson, AZ ", 
"Tulsa-Bartlesville, OK ", "Tupelo, MS ", "Twin Falls, ID ", 
"Virginia Beach-Norfolk-Newport News, VA-NC ", "Washington-Baltimore-Northern Virginia, DC-MD-VA-WV ", 
"Waterloo-Cedar Falls, IA ", "Wausau-Merrill, WI ", "Wenatchee, WA ", 
"Wichita-Winfield, KS ", "Wichita Falls, TX "), class = "factor"), 
    to_EA = structure(c(49L, 127L, 127L, 49L, 114L, 114L, 114L, 
    114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 
    114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 
    114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 112L, 112L, 
    112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 
    112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 
    112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 
    112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 
    112L, 112L, 112L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 
    48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L
    ), .Label = c("Aberdeen, SD ", "Abilene, TX ", "Albany-Schenectady-Amsterdam, NY ", 
    "Albany, GA ", "Albuquerque, NM ", "Alpena, MI ", "Amarillo, TX ", 
    "Anchorage, AK ", "Appleton-Oshkosh-Neenah, WI ", "Asheville-Brevard, NC ", 
    "Atlanta-Sandy Springs-Gainesville, GA-AL ", "Augusta-Richmond County, GA-SC ", 
    "Austin-Round Rock, TX ", "Bangor, ME ", "Baton Rouge-Pierre Part, LA ", 
    "Beaumont-Port Arthur, TX ", "Bend-Prineville, OR ", "Billings, MT ", 
    "Birmingham-Hoover-Cullman, AL ", "Bismarck, ND ", "Boise City-Nampa, ID ", 
    "Boston-Worcester-Manchester, MA-NH ", "Buffalo-Niagara-Cattaraugus, NY ", 
    "Burlington-South Burlington, VT ", "Cape Girardeau-Jackson, MO-IL ", 
    "Casper, WY ", "Cedar Rapids, IA ", "Champaign-Urbana, IL ", 
    "Charleston-North Charleston, SC ", "Charleston, WV ", "Charlotte-Gastonia-Salisbury, NC-SC ", 
    "Chicago-Naperville-Michigan City, IL-IN-WI ", "Cincinnati-Middletown-Wilmington, OH-KY-IN ", 
    "Clarksburg, WV+Morgantown, WV ", "Cleveland-Akron-Elyria, OH ", 
    "Colorado Springs, CO ", "Columbia-Newberry, SC ", "Columbia, MO ", 
    "Columbus-Auburn-Opelika, GA-AL ", "Columbus-Marion-Chillicothe, OH ", 
    "Corpus Christi-Kingsville, TX ", "Dallas-Fort Worth, TX ", 
    "Davenport-Moline-Rock Island, IA-IL ", "Dayton-Springfield-Greenville, OH ", 
    "Denver-Aurora-Boulder, CO ", "Des Moines-Newton-Pella, IA ", 
    "Detroit-Warren-Flint, MI ", "Dothan-Enterprise-Ozark, AL ", 
    "Dover, DE ", "Duluth, MN-WI ", "El Paso, TX ", "Erie, PA ", 
    "Eugene-Springfield, OR ", "Evansville, IN-KY ", "Fargo-Wahpeton, ND-MN ", 
    "Farmington, NM ", "Fayetteville-Springdale-Rogers, AR-MO ", 
    "Flagstaff, AZ ", "Fort Smith, AR-OK ", "Fort Wayne-Huntington-Auburn, IN ", 
    "Fresno-Madera, CA ", "Gainesville, FL ", "Grand Forks, ND-MN ", 
    "Grand Rapids-Muskegon-Holland, MI ", "Great Falls, MT ", 
    "Greensboro-Winston-Salem-High Point, NC ", "Greenville-Spartanburg-Anderson, SC ", 
    "Greenville, NC ", "Gulfport-Biloxi-Pascagoula, MS ", "Harrisburg-Carlisle-Lebanon, PA ", 
    "Harrisonburg, VA ", "Hartford-West Hartford-Willimantic, CT ", 
    "Helena, MT ", "Honolulu, HI ", "Houston-Baytown-Huntsville, TX ", 
    "Huntsville-Decatur, AL ", "Idaho Falls-Blackfoot, ID ", 
    "Indianapolis-Anderson-Columbus, IN ", "Jackson-Yazoo City, MS ", 
    "Jacksonville, FL ", "Johnson City-Kingsport-Bristol (Tri-Cities), TN-VA ", 
    "Jonesboro, AR ", "Joplin, MO ", "Kansas City-Overland Park-Kansas City, MO-KS ", 
    "Kearney, NE ", "Kennewick-Richland-Pasco, WA ", "Killeen-Temple-Fort Hood, TX ", 
    "Knoxville-Sevierville-La Follette, TN ", "La Crosse, WI-MN ", 
    "Lafayette-Acadiana, LA ", "Lake Charles-Jennings, LA ", 
    "Las Vegas-Paradise-Pahrump, NV ", "Lewiston, ID-WA ", "Lexington-Fayette-Frankfort-Richmond, KY ", 
    "Lincoln, NE ", "Little Rock-North Little Rock-Pine Bluff, AR ", 
    "Los Angeles-Long Beach-Riverside, CA ", "Louisville-Elizabethtown-Scottsburg, KY-IN ", 
    "Lubbock-Levelland, TX ", "Macon-Warner Robins-Fort Valley, GA ", 
    "Madison-Baraboo, WI ", "Marinette, WI-MI ", "Mason City, IA ", 
    "McAllen-Edinburg-Pharr, TX ", "Memphis, TN-MS-AR ", "Miami-Fort Lauderdale-Miami Beach, FL ", 
    "Midland-Odessa, TX ", "Milwaukee-Racine-Waukesha, WI ", 
    "Minneapolis-St. Paul-St. Cloud, MN-WI ", "Minot, ND ", "Missoula, MT ", 
    "Mobile-Daphne-Fairhope, AL ", "Monroe-Bastrop, LA ", "Montgomery-Alexander City, AL ", 
    "Myrtle Beach-Conway-Georgetown, SC ", "Nashville-Davidson-Murfreesboro-Columbia, TN ", 
    "New Orleans-Metairie-Bogalusa, LA ", "New York-Newark-Bridgeport, NY-NJ-CT-PA ", 
    "Oklahoma City-Shawnee, OK ", "Omaha-Council Bluffs-Fremont, NE-IA ", 
    "Orlando-The Villages, FL ", "Paducah, KY-IL ", "Panama City-Lynn Haven, FL ", 
    "Pendleton-Hermiston, OR ", "Pensacola-Ferry Pass-Brent, FL ", 
    "Peoria-Canton, IL ", "Philadelphia-Camden-Vineland, PA-NJ-DE-MD ", 
    "Phoenix-Mesa-Scottsdale, AZ ", "Pittsburgh-New Castle, PA ", 
    "Portland-Lewiston-South Portland, ME ", "Portland-Vancouver-Beaverton, OR-WA ", 
    "Pueblo, CO ", "Raleigh-Durham-Cary, NC ", "Rapid City, SD ", 
    "Redding, CA ", "Reno-Sparks, NV ", "Richmond, VA ", "Roanoke, VA ", 
    "Rochester-Batavia-Seneca Falls, NY ", "Sacramento-Arden-Arcade-Truckee, CA-NV ", 
    "Salina, KS ", "Salt Lake City-Ogden-Clearfield, UT ", "San Angelo, TX ", 
    "San Antonio, TX ", "San Diego-Carlsbad-San Marcos, CA ", 
    "San Jose-San Francisco-Oakland, CA ", "Santa Fe-Espanola, NM ", 
    "Sarasota-Bradenton-Venice, FL ", "Savannah-Hinesville-Fort Stewart, GA ", 
    "Scotts Bluff, NE ", "Scranton-Wilkes-Barre, PA ", "Seattle-Tacoma-Olympia, WA ", 
    "Shreveport-Bossier City-Minden, LA ", "Sioux City-Vermillion, IA-NE-SD ", 
    "Sioux Falls, SD ", "South Bend-Mishawaka, IN-MI ", "Spokane, WA ", 
    "Springfield, IL ", "Springfield, MO ", "St. Louis-St. Charles-Farmington, MO-IL ", 
    "State College, PA ", "Syracuse-Auburn, NY ", "Tallahassee, FL ", 
    "Tampa-St. Petersburg-Clearwater, FL ", "Texarkana, TX-Texarkana, AR ", 
    "Toledo-Fremont, OH ", "Topeka, KS ", "Traverse City, MI ", 
    "Tucson, AZ ", "Tulsa-Bartlesville, OK ", "Tupelo, MS ", 
    "Twin Falls, ID ", "Virginia Beach-Norfolk-Newport News, VA-NC ", 
    "Washington-Baltimore-Northern Virginia, DC-MD-VA-WV ", "Waterloo-Cedar Falls, IA ", 
    "Wausau-Merrill, WI ", "Wenatchee, WA ", "Wichita-Winfield, KS ", 
    "Wichita Falls, TX "), class = "factor"), flow = c("9", "6", 
    "25", "8", "194", "36", "49", "31", "42", "11", "118", "75", 
    "111", "43", "14", "1247", "59", "7", "361", "54", "127", 
    "44", "48", "9", "23", "128", "935", "16", "4", "45", "74", 
    "139", "37", "43", "23", "8", "20", "60", "3", "6", "11", 
    "144", "13", "19", "4", "2", "1", "86", "14", "23", "150", 
    "40", "7", "43", "3", "624", "6", "83", "24", "19", "50", 
    "14", "7", "104", "889", "28", "87", "8", "4", "2", "61", 
    "13", "17", "76", "145", "29", "17", "154", "25", "51", "4", 
    "9", "56", "14", "48", "33", "16", "7", "41", "19", "52", 
    "60", "53", "24", "4", "41", "62", "32", "60", "14"), sameEA = c(0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0)), row.names = c(NA, 100L), class = "data.frame")

Here is the code I tried using. What I want it to do is put a 1 in df$sameEA only if the values match within the same row, but when I run it, it puts a 1 in all rows.

for (i in df$from_EA){
if (i %in% df$to_EA)
df$sameEA <-1}

Try

DF$sameEA <- as.numeric(DF$from_EA == DF$to_EA)

The comparison == returns TRUE or FALSE and as.numeric converts those to 1 or 0.