Nizamuddin Siddiqui has Published 2303 Articles

How to round correlation values in the correlation matrix to zero decimal places in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 09:57:20

4K+ Views

To find the correlation matrix, we simply need to use cor function with the data frame object name. For example, if we have a data frame named as df then the correlation matrix can be found by using cor(df). But the result will have too many decimal places to represent ... Read More

How to find the root mean square of a vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 09:40:27

840 Views

To find the root mean square of a vector we can find the mean of the squared values then take the square root of the resulting vector. This can be done in a single and very short line of code. For example, if we have a vector x and we ... Read More

How to create blue or red colored boxplots in R using ggplot2?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 09:38:22

253 Views

The default color of boxplot area in R using ggplot2 is white but we might want to change that color to something more attracting, for example blue or red. To do this purpose, we can use geom_boxplot function of ggplot2 package with fill argument by passing the color names.Consider the ... Read More

How to fill the NA with last observation in the column of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 09:33:35

502 Views

There are multiple ways to fill missing values in data analysis and one of the ways is filling them with the previous value in the same column of the data frame. For example, if we have a column x in data frame df and this columns x contains some NA ... Read More

How to create a subset of an R data frame having complete cases of a particular column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 09:25:49

371 Views

If we have missing values in a data frame then all the values cannot be considered complete cases and we might want to extract only values that are complete. We might want extract the complete cases for a particular column only. Therefore, we can use negation of is.na for the ... Read More

How to create a random sample of some percentage of rows for a particular value of a column from an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 09:10:04

974 Views

Random sampling is an important part of data analysis, mostly we need to create a random sample based on rows instead of columns because rows represent the cases. To create a random sample of some percentage of rows for a particular value of a column from an R data frame ... Read More

How to create a barplot with one of the bars having different color in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 09:06:57

575 Views

A bar plot represents discrete data and the bars in the bar plot are usually of same color but we might want to highlight a particular bar based on the characteristics of the data or the objective of the analysis project. For example, if a particular bar represents highly severe ... Read More

How to add a string before each numeric value in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 14-Oct-2020 09:03:10

5K+ Views

Sometimes the unique identity column of a data frame is not recorded as intended, it contains only numeric values that does not solve the data characteristic purpose. Therefore, we might want to add a string before those numeric values to make the data more sensible for viewers and analysts. This ... Read More

How to calculate population variance in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Oct-2020 13:22:31

608 Views

There is no function in R to calculate the population variance but we can use the population size and sample variance to find it. We know that the divisor in population variance is the population size and if we multiply the output of var(it calculates sample variance) function with (population ... Read More

How to select only one column from an R data frame and return it as a data frame instead of vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Oct-2020 13:20:40

392 Views

Generally, if we extract a single column from an R data frame then it is extracted as a vector but we might want it in data frame form so that we can apply operations of a data frame on it. Therefore, we can use single square brackets for the extraction ... Read More

Advertisements