Nizamuddin Siddiqui has Published 2307 Articles

How to create a new column for factor variable with changed factor levels by using mutate of dplyr package in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:02:59

868 Views

We know that a factor variable has many levels but it might be possible that the factor levels we have are not in the form as needed. For example, if we want to have capital letters as a factor level but the original data has small letters of English alphabets. ... Read More

How to add a new column at the front of an existing R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:00:55

2K+ Views

Generally, when we add a new column to an existing R data frame that column is added at the end of the columns but we might need it at the front. This totally depends on our ease of use, familiarity with variables, and their need. We can add a new ... Read More

How to replace the values in a matrix with another value based on a condition in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 11:58:07

3K+ Views

A matrix has only numeric values and sometimes these values are either incorrectly entered or we might want to replace some of the values in a matrix based on some conditions. For example, if we have few fives in a matrix then we might want to replace all fives to ... Read More

How to extract a single column of an R data frame as a data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 11:55:00

248 Views

Generally, we extract columns as a vector from an R data frame but sometimes we might need a column as a data frame, therefore, we can use as.data.frame to extract columns that we want to extract as a data frame with single square brackets. The purpose behind this could be ... Read More

How to stop par(mfrow) to create multiple plots in one plot window and create only one plot in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 11:53:25

1K+ Views

When we use par(mfrow), we define the number of plots we want to draw on the plot window and when we draw all the necessary plots then starts again with the first plot. For example, if we set par(mfrow) to (2, 2) then we will have four plots on the ... Read More

How to convert a data frame to a matrix if the data frame contains factor variable as strings in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 11:50:16

437 Views

A matrix contains only numeric values, therefore, if we will convert a data frame that has factor variables as strings then the factor levels will be converted to numbers. These numbering is based on the first character of the factor level, for example, if the string starts with an A ... Read More

How to change number formatting from scientific to numbers of axes labels in a scatterplot using ggplot2 package in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 11:48:47

352 Views

When we create a scatterplot or any other plot and the values are presented in scientific form in the original data then the axes values of the plot are also plotted in scientific form. This makes the plot ambiguous, therefore, reading the plot or interpreting it becomes difficult. Hence, we ... Read More

How to manage top and bottom spaces of a bar plot using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 11:47:07

2K+ Views

A bar plot is one of the most commonly used plots for categorical data and it can be easily done in R with the help of ggplot2. When we create a bar plot using ggplot2, there exists some space between bars and the X-axis and the largest bar and top ... Read More

How to add a prefix to columns of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 11:44:57

1K+ Views

If we want to provide more information about the data, we have in columns of an R data frames then we might want to use prefixes. These prefixes help everyone to understand the data, for example, we can use data set name as a prefix, the analysis objective as a ... Read More

How to get list of all columns except one or more columns from an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 11:43:22

1K+ Views

Sometimes, we want to use some columns of an R data frame for analysis, therefore, it is better to get a list of all the columns that we need. In this way, we don’t have to worry about the column operations, if required because we will be having only necessary ... Read More

Advertisements