Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 88 of 196

How to create a covariance matrix in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 754 Views

To create a covariance matrix, we first need to find the correlation matrix and a vector of standard deviations is also required. The correlation matrix can be found by using cor function with matrix object. For example, if we have matrix M then the correlation matrix can be found as cor(M). Now we can use this matrix to find the covariance matrix but we should make sure that we have the vector of standard deviations.Example1> M1 M1Output [, 1] [, 2] [, 3] ...

Read More

How to find the residual of a glm model in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

In a linear model, a residual is the difference between the observed value and the fitted value and it is not different for a general linear model. The difference between linear model and the general linear model is that we use a probability distribution to create a general linear model. If we want to find the residual for a general linear model then resid function can be used just like it is used with the linear model.Example1Consider the below data frame:> x1 y1 df1 df1Output x1 y1 1 4 2 2 3 3 3 5 3 4 4 2 5 ...

Read More

How to create a bar chart using plotly in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 471 Views

Plotly in R is a package specifically designed to create highly-interactive and publication-quality charts. The chart can be created by using plot_ly function of the package and there are three main arguments of plot_ly defined as x, y, and type, where x refers to the X-axis, y refers to the Y-axis and type refers to the chart type but the axes values are stored in a data frame or itself a shared.ExampleLoading plotly package:> library(plotly)Consider the below data frame:> x count df dfOutputx count 1 A 321 2 B 324 3 C 320 4 D 328Creating the bar plot for ...

Read More

How to display the curve on the histogram using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

Mostly, we use histogram to understand the distribution of a variable but if we have an overlay line on the histogram that will make the chart smoother, thus understanding the variation will become easy. To display the curve on the histogram using ggplot2, we can make use of geom_density function in which the counts will be multiplied with the binwidth of the histogram so that the density line will be appropriately created.ExampleConsider the below data frame:> x df head(df, 20)Output x 1 4 2 5 3 6 4 4 5 9 6 ...

Read More

How to create a vector of lists in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 616 Views

If we have many lists but we want to use the values in the lists as a vector then we first need to combine those lists and create a vector. This can be done by using unlist function along with the combine function c to create the vector. For example, if we have two lists defined as List1 and List2 and we want to create a vector V using these lists then it can be created as:V x1 x1Output$a [1] -0.6972237 -1.5013768 -0.2451809 -0.2365569 -1.6304919 -1.1704378 [7] 1.1617054 -0.2349498 -1.2582229 0.4112065 $b [1] 2 0 2 6 0 0 ...

Read More

How to replace a sub-string with the reverse of that sub-string in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 186 Views

The chartr function in base R helps us to replace old strings with new strings and hence it can be also used to replace a subs-string with the reverse of that substring. For example, if we have a vector say x that contains tutorialpsoint and we want to convert it to tutorialspoint then it can be done as chartr("tutorialpsoint ", " tutorialspoint ", x).Example1> x1 x1Output[1] "IDNIA"Example> chartr("DN", "ND", x1)Output[1] "INDIA" Example2> x2 x2Output[1] "IDNIA" "IDNIA" "IDNIA" "IDNONESIA" "IDNIA" "IDNONESIA" [7] "IDNONESIA" "IDNIA" "IDNONESIA" "IDNIA" "IDNIA" "IDNONESIA" [13] "IDNONESIA" "IDNONESIA" "IDNIA" "IDNONESIA" "IDNIA" "IDNIA" [19] "IDNONESIA" "IDNONESIA" "IDNIA" "IDNONESIA" "IDNIA" ...

Read More

How to find the mean of row values in an R data frame using dplyr?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

The mean of row values can be found by using rowwise function of dplyr package along with the mutate function to add the new column of means in the data frame. The rowwise function actually helps R to read the values in the data frame rowwise and then we can use mean function to find the means as shown in the below examples.Example1Consider the below data frame:> x1 x2 df1 df1Output x1 x2 1 0 8 2 2 3 3 2 5 4 0 5 5 3 2 6 0 10 7 3 5 8 1 7 9 0 4 ...

Read More

How to perform chi square test for goodness of fit in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 4K+ Views

The chi square test for goodness of fit is a nonparametric test to test whether the observed values that falls into two or more categories follows a particular distribution of not. We can say that it compares the observed proportions with the expected chances. In R, we can perform this test by using chisq.test function. Check out the below examples to understand how it is done.Example1> x1 x1Output[1] 9 4 1 9 6 6 1 6 0 0 5 8 8 3 7 8 0 3 3 9 6 0 3 8 2 0 8 5 9 1 3 4 ...

Read More

What are the different types of point available in geom_point of ggplot2 package in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 329 Views

We can create a point chart using ggplot2 package but that point not necessarily to be in circular shape, we have twenty-five shape options for those points in ggplot2. While creating a point chart using ggplot2, we can use shape argument inside geom_point to see the difference among these twenty-five shapes.ExampleConsider the below data frame:> set.seed(1957) > x y df dfOutput x y 1 0.7028704 1.6664500 2 0.9672393 1.0456639 3 1.3102736 0.2495795 4 0.3389941 0.2141513 5 0.5867095 0.4417377 6 0.4257543 0.6533757 7 0.9106756 0.3611954 8 1.0444729 1.3770588 9 ...

Read More

How to find the correlation coefficient between two data frames in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 4K+ Views

If two data frames in R have equal number of columns then we can find the correlation coefficient among the columns of these data frames which will be the correlation matrix. For example, if we have a data frame df1 that contains column x and y and another data frame df2 that contains column a and b then the correlation coefficient between df1 and df2 can be found by cor(df1, df2).Example1Consider the below data frame:> x1 x2 df1 df1Output x1 x2 1 39.56630 38.25632 2 39.43689 44.14647 3 40.80479 37.43309 4 ...

Read More
Showing 871–880 of 1,958 articles
« Prev 1 86 87 88 89 90 196 Next »
Advertisements