R error in eval Function -


hi i'm trying create function in r clean data... following code part of it.

limpio=function (tabla, campo, campo_conteo){    tabla1<-aggregate(campo_conteo ~ campo, tabla, length)   colnames(tabla1)[2]<-"frecuencia"   tabla2 <- gsub('\\s+','',toupper(tabla1$campo))    view(tabla2) } 

so, when run:

limpio(vendidos, nacionality, customerid) 

i following error:

error in eval(expr, envir, enclos) : object 'customerid' not found

but column exist, don't know what's problem.

colnames(vendidos)   #[1] "id"             "campaignid"     "customerid"     "phoneid"        "name"            #[6] "numbertype"     "number"         "birthday"       "sex"            "holder"         #[11] "holdernumber"   "nacionality"    "address"        "city"           "zip"   

you can't create formula object this. need pass characters function , create formula those:

limpio <- function (tabla, campo, campo_conteo){   f <- as.formula(paste(campo_conteo, campo, sep="~"))   tabla1<-aggregate(f, tabla, length)   colnames(tabla1)[2]<-"frecuencia"   gsub('\\s+','',toupper(tabla1$campo))    }  limpio(vendidos, "nacionality", "customerid") 

alternatively, use non-formula aggregate method.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -