Skip to content

Data Science Tutorials

  • Home
  • R
  • Statistics
  • Course
  • Machine Learning
  • Guest Blog
  • Contact
  • About Us
  • Toggle search form
  • Beginner's Guide to Data Science
    Beginner’s Guide to Data Science Machine Learning
  • learn Hadoop for Data Science
    Learn Hadoop for Data Science Machine Learning
  • Top 10 Data Visualisation Tools
    Top 10 Data Visualisation Tools Every Data Science Enthusiast Must Know Course
  • How to Scale Only Numeric Columns in R
    How to Scale Only Numeric Columns in R R
  • Error in rbind(deparse.level ...) numbers of columns of arguments do not match
    Error in rbind(deparse.level …) numbers of columns of arguments do not match R
  • How to handle Imbalanced Data
    How to handle Imbalanced Data? R
  • Calculate the p-Value from Z-Score in R
    Calculate the p-Value from Z-Score in R R
  • How to Use Italic Font in R
    How to Use Italic Font in R R
How to put margins on tables or arrays in R?

How to put margins on tables or arrays in R?

Posted on November 22November 22 By Jim No Comments on How to put margins on tables or arrays in R?
Tweet
Share
Share
Pin

How to put margins on tables or arrays in R?, I’ll show you how to use the addmargins function in the R programming language to add margins to tables or arrays in this post.

Algorithm Classifications in Machine Learning – Data Science Tutorials

The addmargins function will be used in the tutorial’s two examples to annotate the margin values on table objects.

To be more specific, the instruction includes the following details:

Providing Examples of Data

The data listed below will serve as the foundation for this R tutorial.

data <- data.frame(x1 = c(LETTERS[1:3], "B", "B", "C"),x2 = letters[1:2])
data                                         
   x1 x2
1  A  a
2  B  b
3  C  a
4  B  b
5  B  a
6  C  b

Consider the previous table. It demonstrates how the sample data frame has two variables and six rows.

Boosting in Machine Learning:-A Brief Overview (datasciencetut.com)

Then, using these data, we can build a table object (a contingency table).

tab <- table(data)                        
tab
    x2
x1  a b
  A 1 0
  B 1 2
  C 1 1

Example 1:-Incorporate Sum Margins into the Contingency Table.

Addmargins() Function Utilization

I’ll show you how to add the sum of each row and column to a table’s margins using the addmargins function in Example 1.

Add Significance Level and Stars to Plot in R (datasciencetut.com)

Take into account the R code below:

tab_sum <- addmargins(tab, FUN = sum)   
tab_sum                                       
         x2
x1    a b sum
  A   1 0   1
  B   1 2   3
  C   1 1   2
  sum 3 3   6

As you can see, we have a row and column that contain the sum margins of our data that are annotated.

 Hope you enjoyed it.

Check your inbox or spam folder to confirm your subscription.

What is the best way to filter by row number in R? – Data Science Tutorials

Tweet
Share
Share
Pin
R

Post navigation

Previous Post: How to compare the performance of different algorithms in R?
Next Post: How to do Pairwise Comparisons in R?

Related Posts

  • How to Implement the Sklearn Predict Approach
    How to Implement the Sklearn Predict Approach? R
  • How to Join Multiple Data Frames in R
    How to Join Multiple Data Frames in R R
  • How to do Pairwise Comparisons in R?
    How to do Pairwise Comparisons in R? R
  • How to Use Gather Function in R
    How to Use Gather Function in R?-tidyr Part2 R
  • How to Calculate Relative Frequencies in R
    How to Calculate Relative Frequencies in R? R
  • Crosstab calculation in R
    Crosstab calculation in R R

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • About Us
  • Contact
  • Disclaimer
  • Guest Blog
  • Privacy Policy
  • YouTube
  • Twitter
  • Facebook
  • Defensive Programming Strategies in R
  • Plot categorical data in R
  • Top Data Modeling Tools for 2023
  • Ogive Graph in R
  • Is R or Python Better for Data Science in Bangalore

Check your inbox or spam folder to confirm your subscription.

  • Data Scientist Career Path Map in Finance
  • Is Python the ideal language for machine learning
  • Convert character string to name class object
  • How to play sound at end of R Script
  • Pattern Searching in R
  • How to Add Superscripts and Subscripts to Plots in R?, The basic syntax for adding superscripts or subscripts to charts in R is as follows:
    How to Add Superscripts and Subscripts to Plots in R? R
  • How to Use Mutate function in R
    How to Use Mutate function in R R
  • Best online course for R programming
    Best online course for R programming Course
  • test for normal distribution in r
    Test for Normal Distribution in R-Quick Guide R
  • How to Create Summary Tables in R
    How to Create Summary Tables in R R
  • gganatogram Plot in R
    How to create Anatogram plot in R R
  • How to plot categorical data in R
    Plot categorical data in R R
  • How to Add a title to ggplot2 Plots in R
    How to Add a caption to ggplot2 Plots in R? R

Copyright © 2023 Data Science Tutorials.

Powered by PressBook News WordPress theme