Nizamuddin Siddiqui has Published 2307 Articles

How to calculate the z score for grouped data in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 10:56:35

505 Views

To calculate the z score for grouped data, we can use ave function and scale function. For example, if we have a data frame called df that contains a grouping coloumn say GROUP and a numerical column say Response then we can use the below command to calculate the z ... Read More

How to find the correlation matrix with p-values for an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 10:51:59

9K+ Views

The correlation matrix with p-values for an R data frame can be found by using the function rcorr of Hmisc package and read the output as matrix. For example, if we have a data frame called df then the correlation matrix with p-values can be found by using rcorr(as.matrix(df)).ExampleConsider the ... Read More

How to create horizontal lines for each bar in a bar plot of base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 10:44:37

2K+ Views

To create horizontal lines for each bar in a bar plot of base R, we can use abline function and pass the same values as in the original barplot with h argument that represents horizontal with different color to make the plot a little better in terms of visualization.Example Live DemoxRead More

How to convert the row values in a matrix to row percentage in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 10:38:16

727 Views

To convert the row values in a matrix to row percentage, we can find the row sums and divide each row value by this sum. For example, if we have a matrix called M then we can convert the row values in M to row percentage by using the commandround((M/rowSums(M))*100, ... Read More

How to change the tick size using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 10:31:50

2K+ Views

To change the tick size using ggplot2, we can use theme function with argument axis.ticks.length. For example, if we have a data frame called df that contains two columns say x and y then the scatterplot between x and y with larger size of tick marks can be created by ... Read More

How to combine a data frame and a named vector if name matches with a column in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 10:28:47

606 Views

If we have a data frame that contains a character column and a named vector which has the same names as in the character column of the data frame then we can combine this data frame and the vector by using match function be appropriately defining the names and the ... Read More

How to convert number to words in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 10:21:07

3K+ Views

To convert number to words in an R data frame column, we can use english function from english package. For example, if we have a data frame called df that contains a number column x then we can convert the numbers into words by using the command as.character(english(df$x)).ExampleConsider the below ... Read More

How to find the row product of a matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 10:16:29

961 Views

To find the row product of a matrix in R, we can use apply function along with prod function. For example, if we have a matrix called M then to find the row product of a matrix we can use the command apply(M, 1, prod). We need to remember that ... Read More

How to convert negative values in a matrix to 0 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 10:10:24

4K+ Views

To convert negative values in a matrix to 0, we can use pmax function. For example, if we have a matrix called M that contains some negative and some positive and zero values then the negative values in M can be converted to 0 by using the command pmax(M, 0).ExampleConsider ... Read More

How to minus one column from another in an R matrix?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 07:44:09

5K+ Views

To minus one column from another in an R matrix, we first need to read the matrix as a data frame using as.data.frame then find minus the columns using minus sign and accessing the column of the data frame. To understand how it can be done look at the steps ... Read More

Advertisements