Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 78 of 196

How to create a column with the serial number of values in character column of an R data frame?

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

A group column in an R data frame have duplicate values and we might want to create a column with the serial number based on the values such as first value of the first group gets 1, the same value gets 2 when occurred second time in the same column and so on. This can be done by using ave function as shown in the below examples.ExampleConsider the below data frame −S.No

Read More

How to find the mean of three-dimensional array in R?

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

A three-dimensional array can have matrices of different size and they are not necessarily to be square or rectangular. Also, all the elements in an array are of same data type. If we want to find the mean of a three-dimensional array then apply function can be used where we need to refer the columns and rows of the array elements using combination function.ExampleA1 apply(A1,c(1,2),mean) [,1] [,2] [1,] 5 7 [2,] 6 8ExampleA2

Read More

How to create a rectangle inside boxplot in base R?

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

To create a rectangle inside boxplot in base R, we can use rect function after creating the boxplot. The rect function has many arguments but for the creation of a rectangle only first four are necessary and these are defined as xleft - a vector (or scalar) of left x positions, ybottom - a vector (or scalar) of bottom y positions, xright - a vector (or scalar) of right x positions and ytop - a vector (or scalar) of top y positions.Examplex

Read More

How to create a table of sums of a discrete variable for two categorical variables in an R data frame?

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

If we want to create a table of sums of a discrete variable for two categorical variables then xtabs function can be used. The output will be a contingency table or cross tabulation table which looks like a matrix. For example, if we have a data frame df with two categorical column x and y and a count column freq then the table of sums for freq can be created by using xtabs(freq~x+y,data=df1).ExampleConsider the below data frame −x1

Read More

What is the use of pheatmap function in R?

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

The pheatmap function is used to create clustered heatmaps but we can change the aesthetics of the plot by using color argument which is one of the main functionalities of pheatmap function. There are many other arguments that differentiate pheatmap from heatmap function.Examplelibrary(pheatmap) M1

Read More

How to create a plot in base R without margins?

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

To create a plot without margins, we first need to define that margin in a way that the plot created after that will not have margins and this can be done by using par function. We would need to pass mar function within par function as par(mar=c(0,0,0,0)).Examplepar(mar=c(0,0,0,0)) plot(1:10)OutputExamplebarplot(1:10)Output

Read More

How to create a plot of Poisson distribution in R?

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

The Poisson distribution is a discrete distribution that has only one parameter named as lambda and it is the rate parameter. The rate parameter is defined as the number of events that occur in a fixed time interval. To create a plot of Poisson distribution in R, we can use the plot function with the density of the Poisson distribution using dpois function.Exampleplot(dpois(x=1:50,lambda=3))OutputExampleplot(dpois(x=1:50,lambda=3),type="l")OutputExampleplot(dpois(x=1:50,lambda=3),type="b")Output

Read More

How to create a matrix without column and row indices in R?

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

To create a matrix without column and row indices, we first need to create the matrix and then prmatrix function can be used to convert that matrix without column and row indices but we would need to provide the number of rows inside the function. For example, if we have a matrix M that contains 5 rows and 5 columns then it can be converted to a matrix without column and row indices using prmatrix(M,rowlab=rep("",5),collab=rep("",5)).ExampleM1

Read More

How to find the maximum of each row in an R data frame?

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

Sometimes we need maximum values, it helps us to identify which case or subject occurs at the greatest point hence we can understand the limit for the sample or population under study. If we want to find the maximum of values two or more columns for each row in an R data frame then pmax function can be used.ExampleConsider the below data frame −set.seed(1997) x1

Read More

How to extract the names of vector values from a named vector in R?

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

How to extract the names of vector values from a named vector in R?The names of vector values are created by using name function and the names can be extracted by using the same function. For example, if we have a vector called x that contains five values(1 to 5) and their names are defined as first, second, third, fourth and fifth then the names of values in x can be extracted by using names(x)[x==1].Example1> x1 names(x1) x1Outputone two three four 1 2 3 4Example> names(x1)[x1==1]Output[1] "one"Example> names(x1)[x1==2]Output[1] "two" Example> names(x1)[x1==3]Output[1] "three"Example> names(x1)[x1==4]Output[1] "four" Example2> x2 x2Output [1] 3 5 ...

Read More
Showing 771–780 of 1,958 articles
« Prev 1 76 77 78 79 80 196 Next »
Advertisements