title: How to add the total sums to the table and get proportion for each cell in R
body: <p>I'm trying to get a proportion for each cell by dividing each row by the row sum, but R gives me an Error saying, </p>
  
  <blockquote>
    <p>Error in data.table$Country : $ operator is invalid for atomic vectors</p>
  </blockquote>
  
  <p>How can I fix this? Also, how can add total sum values for the entire columns and rows to data.table? I get this values when I run <code>addmargins(data.table)</code>, but I'd like to attach the sums to my dataframe. </p>
  
  <hr>
  
  <p>Here's my code:</p>
  
  <pre><code>x = c(40,50,30,30,50)                
  y = c(40,20,30,40,45)                              
  data.table = rbind(x,y)   
  data.table
  dimnames(data.table)=list("Country"=c("England","Germany"),"Score"=c("Q-Score","T-score","X-score","Y-score","Z-score"))
  addmargins(data.table)
  table(data.table$Country,data.table$Score/rowSums(table(data.table&amp;Country,data.table$Score)))
  </code></pre>