Nizamuddin Siddiqui has Published 2307 Articles

How to replace zero with previous value in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Nov-2021 05:05:34

693 Views

To replace zero with previous value in an R data frame column, we can use na.locf function of zoo package but to apply this we first need to replace the zero values with NA.For example, if we have a data frame called df that contains a column say Rate then ... Read More

Create scatterplot for two dependent variables and one independent variable in R.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Nov-2021 04:40:13

2K+ Views

To create scatterplot for two dependent variables and one independent variable, we can use geom_point function and geom_smooth function of ggplot2 package. Both of these functions will be used twice, where we can define the aesthetics of the plot for each dependent variable as shown in the Example below.ExampleFollowing snippet ... Read More

How to draw concentric circles with dark borders in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Nov-2021 04:32:01

77 Views

To draw concentric circles, we can use draw.circle function of plotrix package where we can put lwd argument but firstly we would need to create a blank graph with plot function as shown below.For Example, we can create three concentric circles at position X=5 and Y=5 having radius of 1, ... Read More

How to create matrix diagram in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Nov-2021 04:19:21

262 Views

To create matrix diagram, we can use corrplot function of corrplot function. For this purpose, we would need to set is.corr argument to FALSE so that the matrix values will be plotted in the diagram. Otherwise, the corrplot function requires correlation matrix instead of a matrix.Check out the Example given ... Read More

Create line chart for mean covered with minimum and maximum in R.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Nov-2021 04:13:33

836 Views

To create line chart for mean covered with minimum and maximum in R, we first need to create columns for row means, row minimum, and row maximum after that geom_line function can be used along with geom_ribbon function of ggplot2 package as shown in the below example.ExampleFollowing snippet creates a ... Read More

How to add two columns if both contains missing values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 13:44:36

828 Views

If we want to add two columns of an R data frame and each of them contains missing values then the addition of columns can be done in one of the following ways −Adding both the column values if they are numeric.Returning numeric if one of the columns has missing ... Read More

How to take transpose of vectors stored in an R list?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 13:27:50

229 Views

We can take the transpose of vectors stored in an R list by using Map function with do.call. For example, if we have a list called LIST that contains say ten vectors then we can transpose these vectors by using the command given below − do.call(Map, c(f=c, LIST))Check out the ... Read More

How to subset a matrix based on values in a particular column in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 13:23:22

3K+ Views

To subset a matrix based on values in a particular column, we can use single square brackets and provide the row and column values. The column values will be set for the columns that we want to subset and the row value will be set for the values of the ... Read More

How to highlight outliers in a boxplot in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 13:18:52

498 Views

To highlight outliers in a boxplot, we can create the boxplot with the help of Boxplot function of car package by defining the id.method.For example, if we have a vector called V then the boxplot of V with highlighted outliers can be created by using the below given command −Boxplot(~V, ... Read More

How to create an exponential distribution plot in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 13:15:24

703 Views

To create an exponential distribution plot, we can use curve function.For example, if we want to create a exponential distribution plot for 100 values with rate parameter equal to ½ then we can use the command given below:curve(dexp(x, rate=1/2), xlim=c(1, 50))Check out the below examples to understand how it works.Example ... Read More

Advertisements