Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 88 of 196

How to standardized a column in an R data frame?

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

The standardization means converting a vector or column of an R data frame in a way such that the mean of the same becomes 0 and the standard deviation becomes 1, that is it should be converted to standard normal distribution. In R, it can be easily done with the help of scale function. Check out the below example to understand how it is done.ExampleConsider the below data frame:> set.seed(3665) > x1 x2 x3 x4 x5 x6 df dfOutputx1 x2 x3 x4 x5 x6 1 1.3958185 49.39843 128.5224 3 4.183664 2.33406246 2 1.0467979 48.90103 120.5796 7 3.526731 0.02043217 3 0.9190516 ...

Read More

How to extract columns based on particular column values of an R data frame that matchna pattern?

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

The column values of an R data frame can be easily extracted by subsetting with single square brackets but if we want to extract the column values that match a pattern then we need to use grepl function inside single square brackets, this will help us to match the pattern of the values in the data frame columns.ExampleConsider the below data frame:> set.seed(271) > x1 x2 df1 df1Output x1 x2 1 A242 B71 2 A123 B71 3 A242 B81 4 A242 B87 5 A123 B71 6 A321 B71 7 A187 ...

Read More

How to remove rows based on blanks in a column from a data frame in R?

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

Sometimes data is incorrectly entered into systems and that is the reason we must be careful while doing data cleaning before proceeding to analysis. A data collector or the sampled unit might enter blank to an answer if he or she does not find an appropriate option for the question. This also happens if the questionnaire is not properly designed or blank is filled by mistake. Also, if we have categorical variable then a control category might be filled with blank or we may want to have a blank category to use a new one at later stage. Whatever the ...

Read More

How to create a data frame in R with list elements?

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

If a list has the same length of elements (not sub-elements) as the length of each vector for which we want to create the data frame then we first need to create the data frame of vectors then we can easily add the list into the data frame. But if we have a list and other vectors then data frame cannot be created as data.frame function will read each value of the list separately.Example> df1 df1Output   x y 1  6 1 2  8 1 3  6 2 4  8 1 5  5 1 6  3 1 7  6 1 8 ...

Read More

How to reduce a matrix in R to echelon form?

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

The echelon form of a matrix is the matrix that has the following characteristics:1. The first non-zero element in each row, called the leading entry, is 1.2. Each leading entry is in a column to the right of the leading entry in the previous row.3. Rows with all zero elements, if any, are below rows having a non-zero element.In R, we can use echelon function of matlib package to find the echelon form of the matrix.Example> M MOutput [, 1] [, 2] [, 3] [, 4] [, 5] [1, ] 8 11 3 10 13 [2, ] 9 ...

Read More

How to find the sum of two list elements in R?

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

The list elements of two lists cannot be added directly but we can do this addition by unlisting the elements. To do this, we would need to use lapply function. For example, if we have two lists defined as x and y then the sum of the elements in these lists can be calculated as follows:Examplelapply(seq_along(x), function(i) unlist(x[i])+unlist(y[i]))Example1> x1 x1Output[[1]] [1] 0 3 0 1 2 0 1 0 1 3 3 0 0 0 1 1 0 1 0 1 1 0 2 0 0 6 1 2 1 1 1 1 2 1 1 0 0 [38] 2 ...

Read More

How to create a bar plot using ggplot2 with one bar having black border in R?

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

The bar plot can be easily created with the help of geom_bar. But if we want to have a different border for a particular bar then we first need to create the bar plot and store it in an object. After that we need to add the original plot with the bar for which we want to have a black border. Check out the below example to understand how it can be done.ExampleConsider the below data frame:> Group Freq df dfOutput Group Freq 1 G1 18 2 G2 27 3 G3 24Loading ggplot2 package ...

Read More

How to perform post hoc test for Kruskal-Wallis in R?

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

The Kruskal-Wallis test is the non-parametric analogue of one-way analysis of variance. The non-parametric tests are used in situations when the assumptions of parametric tests are not met. If we find significant difference in Kruskal-Wallis then post hoc tests are done to find where the difference exists. For this purpose, we can perform dunn test. The function of dunn test can be accessed through FSA package.Example1Loading FSA package:> library(FSA)Consider the below data frame:> x1 y1 df1 df1Output  x1 y1 1 E 1.1191117 2 D 1.1276032 3 D 1.5610692 4 E 1.1585054 5 E 1.0239322 6 C 0.8000165 ...

Read More

How to create an empty plot using ggplot2 in R?

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

The two most easy ways to create an empty plot using ggplot2 are using geom_blank function and also adding the theme_bw along with the geom_blank. The geom_blank will create an empty plot with white gridlines and grey background, on the other hand, addition of theme_bw will create the empty plot with grey gridlines and white background.ExampleConsider the below data frame:> set.seed(151) > x y df dfOutput      x         y 1  -0.05153895 0.3139643 2   0.76573738 0.1816184 3  -0.14673959 0.8201743 4  -0.11318581 1.6005576 5  -0.39551140 0.6770630 6  0.78227595 0.7446956 7  -1.39747811 0.7004385 8  -1.01883832 1.2728014 9 ...

Read More

How to find the mean of a square matrix elements by excluding diagonal elements in R?

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

There are many ways to find the mean of a matrix elements by excluding diagonal elements, this mean is actually the mean of lower triangular matrix and the upper triangular matrix. We can simply use mean function by creating a vector of lower and upper triangular matrix as shown in the below examples.Example1> M1 M1Output   [, 1] [, 2] [, 3] [, 4] [1, ] 1    6    3    6 [2, ] 8    5    3    4 [3, ] 5    4    4    6 [4, ] 5    5    3    4 [5, ...

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