<div dir="ltr"><div><div><div><div><div><div><div>Hi,<br><br></div>I'm new to R and data.table and having some difficulties with a certain function that I wrote.<br></div><br></div>the function code:<br><br>freq_per = function(data,byWhat,month){<br>
for (i in 1:length(month)){<br> data = data.table(data)<br> data[,percent :=sum(freq),by = byWhat]<br> data[,percent := (freq/percent)*100]<br> data = data.frame(data)<br> data$percent = format(round(data$percent),nsmall = 2)<br>
}<br> data<br> <br>}<br><br></div>I have tried to call the function with freq_per(data,list(BlaBla),month) and get the error message from the topic.<br><br>I have tried to create a global variable with byWhat = list(BlaBla), it didn't work because the object 'BlaBla' not found.<br>
<br></div>I also tried to use keyby instead of by with c(colnames(data)[1]), but the results that I got are not right.<br><br></div>anybody has an idea how to overcome the problem?<br><br></div>Thanks.<br><div><div><div>
<div><div><div><div><br><br></div></div></div></div></div></div></div></div>