Nizamuddin Siddiqui has Published 2307 Articles

How to find the row wise sum for n number of columns in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 23-Nov-2021 06:36:30

3K+ Views

To find the row wise sum of n number of columns can be found by using the rowSums function along with subsetting of the columns with single square brackets.For example, if we have a data frame called df that contains five columns and we want to find the row sums ... Read More

How to extract the maximum value from named vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 23-Nov-2021 06:31:08

750 Views

To extract the maximum value from named vector in R, we can use which.max function.For example, if we have a vector called X which is a named vector then we can use the following command to find the maximum value in X.X[which.max(X)]Check out the below examples to understand how it ... Read More

How to reduce the space between Y-axis value and ticks using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 23-Nov-2021 06:21:07

4K+ Views

To reduce the space between axis value and ticks using ggplot2, we can use theme function of ggplot2 package with margin set to 0.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 reduced ... Read More

How to display fraction in base R plot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 23-Nov-2021 06:15:23

930 Views

To display fraction in base R plot, we can use frac function in text function.For example, if we create a plot of vectors called X and Y with display of over form fraction as X over Y at X=2 and Y= 2 then we can use the following code −text(2, ... Read More

How to display fraction in a plot title using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 23-Nov-2021 06:11:56

822 Views

To display fraction in a plot title using ggplot2 in R, we can use frac function inside ggtitle function of ggplot2 package. Generally, fraction is displayed as X/Y but frac function helps to create the fraction in over form.Check out the below example to understand how over form of fraction ... Read More

How to find the sequence of correlation between variables in an R data frame or matrix?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 23-Nov-2021 05:51:00

199 Views

To find the sequence of correlation between variables in an R data frame or matrix, we can use correlate and stretch function from corrr package.For example, if we have a data frame called df then we can find the sequence of correlation between variables in df by using the below ... Read More

How to create a matrix with vectors as elements in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 23-Nov-2021 05:45:59

573 Views

To create a matrix with vectors as elements in R, we can create arrays because an array contains matrices with vectors as elements.Check out the below given examples of arrays and vectors extracted by the arrays to understand how matrices stored in an array represent vectors as elements.Example 1Following snippet ... Read More

How to create a vertical line in a time series plot in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 23-Nov-2021 05:42:07

848 Views

To create a time series plot, we can use simply apply plot function on time series object and if we want to create a vertical line on that plot then abline function will be used with v argument.For example, if we have a time series object called T and we ... Read More

How to change the order of a matrix in increasing order based on a single column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 23-Nov-2021 05:40:26

291 Views

To change the order of a matrix in increasing order based on a single column in R, we can use order function after subsetting a particular column.For example, if we have a matrix called M and we want to change the order of M in increasing order based on first ... Read More

How to convert matrices stored in a list into vectors in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 23-Nov-2021 05:34:15

106 Views

A list may contain vectors, data frames, matrices, lists etc. If a list contains matrices and we want to convert those matrices into vectors then lapply function can be used along with as.vector function.For example, if we have a list called LIST that contains matrices then we can convert those ... Read More

Advertisements