我定義了以下函式:
counter<-function(data,varname){
data[is.na(varname),.N]
}
當我傳遞引數時:
counter(df,ip_address_ts)
我收到錯誤:
Error in .checkTypos(e, names_x) : Object 'ip_address_ts' not found. Perhaps you intended ip_address_ts, email_address_ts
ip_address_ts 在 df 中,為什么這不起作用?
uj5u.com熱心網友回復:
您的代碼正在查找物件ip_address_ts,而不是字串"ip_address_ts"
counter(df, "ip_address_ts")
uj5u.com熱心網友回復:
解決方案是使用 get 然后將列名作為字串傳遞:
counter<-function(data,varname){
data[is.na(get(varname)),.N]
}
counter(df,"ip_address_ts")
有關此提示和其他提示,請查看此鏈接:
http://brooksandrew.github.io/simpleblog/articles/advanced-data-table/#3-functions
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/348630.html
