比賽我想在河替代DT1.x與DT2.y時DT1.x和DT2.x R中
做到這一點使用數據表於是我開始與這個
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
在哪裏dtMain$State == statesFile$state
,我想statesFile$stateExpan
更換dtMain$State
和得到這個
dtMain
Name state
1: CompanyA California
2: CompanyB Minnesota
3: CompanyC California
4: CompanyD Texas
這裏的代碼來創建2個文件
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"))
我的問題是這樣一個 R finding rows of a data frame where certain columns match those of another 一個新的水平,我期待一個數據表解決方案。
你應該用文字來解釋的規則進行了改造,不是簡單地顯示輸入和輸出 – Frank
@ytk不是一個傻瓜,我想,因爲這是有關修改dtMain,不合並,創建一個新表。 – Frank
無論如何,答案是'dtMain [statesFile,on =。(state),state:= i.stateExpan]'我會看看我能否找到更合適的重複。你也可以看看這個用戶編寫的例子:http://stackoverflow.com/documentation/data.table/4976/joins-and-merges/17560 – Frank