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.

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