Nizamuddin Siddiqui has Published 2307 Articles

How to create scatterplot with intercept equals to 1 using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Dec-2020 07:00:50

82 Views

To create a scatterplot with intercept equals to 1 using ggplot2, we can use geom_abline function but we need to pass the appropriate limits for the x axis and y axis values. For example, if we have two columns x and y in a data frame df and both have ... Read More

How to multiply two matrices by elements in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Dec-2020 06:58:46

5K+ Views

To multiply two matrices by elements in R, we would need to use one of the matrices as vector. For example, if we have two matrices defined by names M1 and M2 then the multiplication of these matrices by elements can be done by using M1*as.vector(M2). The main thing we ... Read More

How to create a plot with reversed Y-axis labels in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Dec-2020 06:40:18

1K+ Views

To create a plot with reversed Y-axis we need to use the rev function for the Y-axis labels with ylim but we would also need to define the range for the y-axis values, otherwise, R will throw an error. For example, if we have two vectors named as x and ... Read More

How to create a plot with tick marks between X-axis labels in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Dec-2020 06:37:28

4K+ Views

To create a plot with tick marks manually between X-axis values in base R, we first need to create the plot without X-axis labels then add the axis values using axis function with appropriate labels, this will create tick marks as well as labels. After this step, we would need ... Read More

How to create the boxplots in base R ordered by means?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Dec-2020 06:35:20

77 Views

To create the boxplots in base R ordered by means, we first need to order the categorical column based on the mean of the numerical column and then the boxplot will be created.For example, if we have a data frame df that has a categorical column x and a numerical ... Read More

How to find the column number of a string column based on a string match in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Dec-2020 06:32:00

307 Views

A data frame might be very long and contain columns with only string values as well as numerical values. While doing the analysis, we might want to check which columns contain a particular string value. For example, if we have a column with string values as A, B, and C ... Read More

How to find the mean of a numerical column by two categorical columns in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Dec-2020 06:28:16

873 Views

If we have two categorical columns along with a numerical column in an R data frame then we can find the mean of the numerical column by using the combination of the categorical columns with the help of aggregate function. For example, if a data frame df contains a numerical ... Read More

How to add a variable to the model in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Dec-2020 06:25:50

800 Views

If we want to add variables to the model in base R then update function can be used. The update function will update the previous modle by adding the new variable and this variable can be a single variable as well as an interaction of the two or more also ... Read More

How to find the range for 95% of all values in an R vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Dec-2020 06:21:52

1K+ Views

The range for 95% of all values actually represents the middle 95% values. Therefore, we can find the 2.5th percentile and 97.5th percentile so that the range for middle 95% can be obtained. For this purpose, we can use quantile function in R. To find the 2.5th percentile, we would ... Read More

How to convert NA’s in sequence to a single NA in an R vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Dec-2020 06:19:31

81 Views

Sometimes values are missing in a sequence and R program records them as NA (Not Available). In this type of situation, we might want to replace consecutive NA records with single NA value. This can be done by using is.na along with diff function as shown in the below examples.Example Live ... Read More

Advertisements