I want to do this using data tables in R.
So I start with this
dtMain
Name state
1: CompanyC CA
2: CompanyM MN
3: CompanyC1 California
4: CompanyT TX
statesFile
stateExpan state
1: Texas TX
2: Minnesota MN
3: California CA
Where dtMain$State == statesFile$state
, I want to replace dtMain$State
with statesFile$stateExpan
and get this
dtMain
Name state
1: CompanyA California
2: CompanyB Minnesota
3: CompanyC California
4: CompanyD Texas
Here's code to create the 2 files
library(data.table)
dtMain <- data.table(Name = c("CompanyA" ,"CompanyB","CompanyC","CompanyD"),
state = c("CA","MN","California","TX"))
statesFile <- data.table( stateExpan = c("Texas","Minnesota","California"),
state = c("TX","MN","CA"))
My problem is the next level of this one R finding rows of a data frame where certain columns match those of another and I am looking for a data table solution.