Hi,

I'm new to R and data.table and having some difficulties with a certain
function that I wrote.

the function code:

freq_per = function(data,byWhat,month){
    for (i in 1:length(month)){
        data = data.table(data)
        data[,percent :=sum(freq),by = byWhat]
        data[,percent := (freq/percent)*100]
        data = data.frame(data)
        data$percent = format(round(data$percent),nsmall = 2)
    }
    data

}

I have tried to call the function with freq_per(data,list(BlaBla),month)
and get the error message from the topic.

I have tried to create a global variable with byWhat = list(BlaBla), it
didn't work because the object 'BlaBla' not found.

I also tried to use keyby instead of by with  c(colnames(data)[1]), but the
results that I got are not right.

anybody has an idea how to overcome the problem?

Thanks.
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help

Reply via email to