Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8756205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:01:12+00:00 2026-06-13T14:01:12+00:00

I’m trying to get a proportion for each cell by dividing each row by

  • 0

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,

Error in data.table$Country : $ operator is invalid for atomic vectors

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 addmargins(data.table), but I’d like to attach the sums to my dataframe.


Here’s my 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&Country,data.table$Score)))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:01:13+00:00Added an answer on June 13, 2026 at 2:01 pm

    The output of a call to table is an object of class table. This is basically an array. You cannot use $ to reference arrays or atomic vectors. (Hence the error).

    If you want to assign the results of addmargins(data.table) to an object, then you are more than free to do so

    margin_table <- addmargins(data.table)
    

    It looks like you want to then create a table of the relative proportions.

    prop.table is useful for this.

     prop.table(margin_table)
    
             Score
    Country      Q-Score    T-score X-score    Y-score    Z-score       Sum
      England 0.02666667 0.03333333    0.02 0.02000000 0.03333333 0.1333333
      Germany 0.02666667 0.01333333    0.02 0.02666667 0.03000000 0.1166667
      Sum     0.05333333 0.04666667    0.04 0.04666667 0.06333333 0.2500000
    

    you could also run prop.table on the original to get the row proportions (1 = rows, 2 = columns)

     prop.table(data.table, margins = 1)
          Score
    Country     Q-Score   T-score   X-score   Y-score   Z-score
      England 0.2000000 0.2500000 0.1500000 0.1500000 0.2500000
      Germany 0.2285714 0.1142857 0.1714286 0.2285714 0.2571429
    

    The help file for table (accessed by ?table or help('table') is detailed and contains links to the help files for prop.table and addmargins!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I want to construct a data frame in an Rcpp function, but when I
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.