Nizamuddin Siddiqui has Published 2307 Articles

How to create a contingency table using datasets in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Nov-2020 12:45:58

232 Views

A contingency table is a cross-tabulation that looks like a matrix. These tables can have different as well as equal number of columns and rows. If we want to create a contingency table using datasets in base R then table function can be used. For example, if we want to ... Read More

How to remove NA’s from an R data frame that contains them at different places?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Nov-2020 12:23:26

224 Views

If NA values are placed at different positions in an R data frame then they cannot be easily removed in base R, we would be needing a package for that. The best package to solve this problem is dplyr and we can use summarise_each function of dplyr with na.omit to ... Read More

How to check if a value exists in an R data frame or not?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Nov-2020 12:13:04

7K+ Views

There are many small objectives that helps us to achieve a greater objective in data analysis. One such small objective is checking if a value exists in the data set or not. In R, we have many objects for data set such as data frame, matrix, data.table object etc. If ... Read More

How to create line chart using ggplot2 in R with 3-sigma limits?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Nov-2020 12:09:17

237 Views

To create a line chart with 3-sigma limits using ggplot2, we first need to calculate the limits then the chart can be created. We can use geom_ribbon function of ggplot2 for this purpose where we can pass lower 3-sigma limit for ymin argument in aes and upper 3-sigma limit for ... Read More

How to create a new column in an R data frame based on some condition of another column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Nov-2020 12:04:50

2K+ Views

Sometimes we want to change a column or create a new by using other columns of a data frame in R, this is mostly required when we want to create a categorical column but it can be done for numerical columns as well. For example, we might want to create ... Read More

How to set the alignment of labels in horizontal bar plot to left in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Nov-2020 12:00:15

901 Views

When we create a horizontal bar plot using ggplot2 package, the labels of the categorical variable are aligned to the right-side of the axis and if the size of these labels are different then it looks a little ambiguous. Therefore, we might want to set the alignment of the labels ... Read More

How to draw a circle in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Nov-2020 11:56:43

3K+ Views

There is no direct function in R to draw a circle but we can make use of plotrix package for this purpose. The plotrix package has a function called draw.cirlce which is can be used to draw a circle but we first need to draw a plot in base R ... Read More

How to convert diagonal elements of a matrix in R into missing values?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Nov-2020 11:47:43

695 Views

First thing we need to understand is diagonal elements are useful only if we have a square matrix, otherwise it would not make sense to set diagonal elements, this is known to almost all mathematicians but some freshman might get confused because we can create diagonal in a non-square matrix ... Read More

How to create different Y-axis for group levels using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Nov-2020 11:42:56

737 Views

If we have a categorical variable or a group variable then we might want to create a line chart for each of the categories or levels, this will help us to understand the range of multiple levels in a single plot. For this purpose, we can use facet_grid function of ... Read More

What is the use of type = "h" in base R for plotting a graph?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Nov-2020 11:40:18

2K+ Views

The type = "h" is a graphing argument in base R which is generally used inside a plot function. It helps to generate the vertical lines in the R environment instead of points. For example, if we want to plot values from 1 to 10 then type = "h" will ... Read More

Advertisements