I have defined a following function:
counter<-function(data,varname){
data[is.na(varname),.N]
}
When I pass the arguments:
counter(df,ip_address_ts)
I get the error:
Error in .checkTypos(e, names_x) : Object 'ip_address_ts' not found. Perhaps you intended ip_address_ts, email_address_ts
ip_address_ts is in df, so why does this not work?
CodePudding user response:
Your code is looking the object ip_address_ts
, not the string "ip_address_ts"
counter(df, "ip_address_ts")
CodePudding user response:
Solution is to use get and then pass the column name as string:
counter<-function(data,varname){
data[is.na(get(varname)),.N]
}
counter(df,"ip_address_ts")
For this and other tips check out this link:
http://brooksandrew.github.io/simpleblog/articles/advanced-data-table/#3-functions