Guest User

依條件新增欄位

a guest
Feb 25th, 2020
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.48 KB | None | 0 0
  1. library(data.table)
  2.  
  3. # 假設只有2個區有資料
  4. district <- data.table(name = c('中正區','萬華區'),
  5.                       value = c(5000,  3000))
  6.  
  7. # 原本的資料集
  8. house <- data.table(name = c('中正區','大安區','信義區','松山區','文山區','萬華區'),
  9.                     size = sample(20, 6, replace = T))
  10. # 設置key
  11. setkey(district, 'name')
  12. setkey(house, 'name')
  13.  
  14. # 沒有對應到的可以更改nomatch
  15. district[house, nomatch = NA, mult = 'all']
Add Comment
Please, Sign In to add comment