<div dir="ltr"><div>Hi Kostia,</div><div><br></div>I think that you already have a column named "percent" that has type "character". When you use "format", the result is a character, for example...<div>

<br></div><div>If so -- use str(data) to check -- you'll need to delete it first, using data[,percent:=NULL]. <div><br></div><div>If you're confused about how data.tables work and what they are useful for (...which I think might be the case based on your conversion to a data.frame and use of format), you might want to go through the vignettes and other resources here: <a href="http://datatable.r-forge.r-project.org/">http://datatable.r-forge.r-project.org/</a></div>

</div><div><br></div><div>Best,</div><div><br></div><div>Frank</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 29, 2013 at 9:57 AM, Kostia Kofman <span dir="ltr"><<a href="mailto:kofmank@gmail.com" target="_blank">kofmank@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="text-indent:0px;letter-spacing:normal;font-variant:normal;font-style:normal;background-color:rgb(225,226,229);font-weight:normal;line-height:15px;border-collapse:separate;text-transform:none;font-size:13px;white-space:pre-wrap;font-family:'Lucida Console';word-spacing:0px"><pre style="font-family:'Lucida Console';font-size:10pt!important;outline-style:none;outline-width:initial;outline-color:initial;border-style:none;border-width:initial;border-color:initial;white-space:pre-wrap!important;margin:0px;line-height:1.2">

<span style="color:rgb(197,6,11)">This is the error I receive trying "BlaBla" instead of list(BlaBla)<br></span></pre><pre style="font-family:'Lucida Console';font-size:10pt!important;outline-style:none;outline-width:initial;outline-color:initial;border-style:none;border-width:initial;border-color:initial;white-space:pre-wrap!important;margin:0px;line-height:1.2">

<span style="color:rgb(197,6,11)"><br>Error in `[.data.table`(data, , `:=`(percent, sum(freq)), by = byWhat) : 
  Type of RHS ('integer') must match LHS ('character'). To check and coerce would impact performance too much for the fastest cases. Either change the type of the target column, or coerce the RHS of := yourself (e.g. by using 1L instead of 1)</span></pre>


</span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 29, 2013 at 5:44 PM, Frank Erickson <span dir="ltr"><<a href="mailto:FErickson@psu.edu" target="_blank">FErickson@psu.edu</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><span style="font-family:arial,sans-serif;font-size:13px">Try "BlaBla" instead of list(BlaBla)</span><br>


<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></div><div><span style="font-family:arial,sans-serif;font-size:13px">(oops, forgot to reply to the mailing list the first time I sent this. Sorry for the double email, Kostia.)</span></div>




</div><div class="gmail_extra"><br><br><div class="gmail_quote"><div>On Thu, Aug 29, 2013 at 9:36 AM, Kostia Kofman <span dir="ltr"><<a href="mailto:kofmank@gmail.com" target="_blank">kofmank@gmail.com</a>></span> wrote:<br>




</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><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>
<br></div></div><div>_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br></div></blockquote></div><br></div>



</blockquote></div><br></div>
</div></div></blockquote></div><br></div>