Nizamuddin Siddiqui has Published 2303 Articles

How to join two data frames with the same row order using dplyr in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:50:47

212 Views

When we have one common column in two data frames then joining of those data frames might be used to create a bigger data frame. This will help us to analyze a combined data set with many characteristics. We can do this by using inner_join function of dplyr package.ExampleConsider the ... Read More

How to convert multiple numerical variables to factor variable in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:45:17

2K+ Views

Sometimes the data type for a variable is not correct and it is very common that a factor variable is read as a numeric variable, especially in cases where factor levels are represented by numbers. If we do not change the data type of a factor variable then the result ... Read More

How to create an empty matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:39:17

5K+ Views

An empty matrix can be created in the same way as we create a regular matrix in R but we will not provide any value inside the matrix function. The number of rows and columns can be different and we don’t need to use byrow or bycol argument while creating ... Read More

How to plot means inside boxplot using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:30:27

505 Views

When we create a boxplot, it shows the minimum value, maximum value, first quartile, median, and the third quartile but we might want to plot means as well so that the comparison between factor levels can be made on the basis of means also. To create this type of plot, ... Read More

How to create a scatterplot in R with legend position inside the plot area using ggplot2?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:27:10

339 Views

Legends help us to differentiate the values of the response variable while creating the scatterplot. In this way, we can understand how one level of a factor variable affects the response variable. The legend is preferred to be positioned at left bottom, top right, top left, and bottom right. We ... Read More

How to create a subset for a factor level in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:24:52

4K+ Views

In data analysis, we often deal with factor variables and these factor variables have different levels. Sometimes, we want to create subset of the data frame in R for specific factor levels to analyze the data only for that particular level of the factor variable. This can be simply done ... Read More

How to convert a vector into matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:20:02

12K+ Views

To convert a vector into matrix, just need to use matrix function. We can also define the number of rows and columns, if required but if the number of values in the vector are not a multiple of the number of rows or columns then R will throw an error ... Read More

How to create stacked bar plot in which each bar sum to 1 or 100% in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:14:30

428 Views

A stacked bar plot consists multiple bars in one bar, it shows one category for a categorical variable with its levels. Mostly, the stacked bar chart is created with the count of the levels in each category but if we want to create it with percentage for individual categories of ... Read More

How to create a lagged variable in R for groups?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:11:53

483 Views

Lagged variable is the type of variable that contains the previous value of the variable for which we want to create the lagged variable and the first value is neglected. Therefore, we will always have one missing value in each of the groups, if we are creating a lagged variable ... Read More

How to multiple a matrix rows in R with a vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:08:19

927 Views

When we multiple a matrix with a vector in R, the multiplication is done by column but if we want to do it with rows then we can use transpose function. We can multiply the transpose of the matrix with the vector and then take the transpose of that multiplication ... Read More

Advertisements