Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 114 of 196

How to show all X-axis labels in a bar graph created by using barplot function in R?

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

In base R, the barplot function easily creates a barplot but if the number of bars is large or we can say that if the categories we have for X-axis are large then some of the X-axis labels are not shown in the plot. Therefore, if we want them in the plot then we need to use las and cex.names.ExampleConsider the below data and bar graph −> x names(x) barplot(x)OutputShowing all the X-axis labels −> barplot(x,las=2,cex.names=0.5)Output

Read More

How to concatenate numerical vectors and a string to return a string in R?

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

In general, the concatenation of numerical vectors and string results in a vector of strings in R. For example, if we want to concatenate 1, 2, 3 with Tutorialspoint using paste function then it will result in a vector as: "Tutorialspoint 1" "Tutorialspoint 2" "Tutorialspoint 3". But if we want it to return as "Tutorialspoint 1 2 3" then we need to use collapse argument with paste function.Example1> x1Output[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"> y1Output[1] 1 9 6 3 8 1 8 5 9 1 2 8 3 8 4 5 10 1 6 3 ...

Read More

How to multiply each element of a numerical vector in R?

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

Sometimes we want to determine the multiplication of all the elements of a vector just like the sum. This might be required to test the changes in the mathematical operations that can be applied to a numerical vector. In base R, we have prod function which works same as sum but give us the multiplication of all the elements of a vector.Example> v1 v1Output[1] 1 2 3 4 5> prod(v1)Output[1] 120 Example> v2 v2Output[1] -0.500466629 0.394771317 0.575743107 0.026982141 0.812697502 [6] 0.995708241 2.198243938 -0.008609976 -0.931337300 -0.073743225> prod(v2)Output[1] 3.228448e-06Example> v3 v3Output[1] 1.7328245888 -0.5772304935 2.5161349689 3.0401656274 0.1669773313 [6] -0.0001252235 0.7649984733 2.4901543043 1.5618729422 2.4392364199> ...

Read More

How to combine two vectors while replacing the NA values with the values in the other vector in R?

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

Sometimes we have vectors with NA values, also there might be a situation that one of vector having an NA at a position and the other vector has the numerical values at the same position. For example, 1, 2, NA and 1, 2, 3. In this case, we might want to combine these two vectors to make a single vector. This can be done by using coalesce function of dplyr package.Example> library(dplyr) > x1 x1Output[1] NA 4 NA 1 2 NA 4 1 4 1 2 3 1 4 2 2 NA 2 2 1Example> y1 y1Output[1] 1 2 3 ...

Read More

How to add a citation in a plot created by using ggplot2 in R?

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

A footnote is generally used to give references to a document, text or image and it is called citation. It helps the reader or viewer to check out the original source using the new text or image is generated. If we want to give citation to a plot in R using ggplot2 package then we can add labs that has caption option to add the footnotes.ExampleConsider the below data frame −> set.seed(1) > x y df dfOutput      x       y 1 0.8735462 4.0117812 2 1.6836433 2.8898432 3 0.6643714 1.8787594 4 3.0952808 0.2853001 5 1.8295078 3.6249309 6 ...

Read More

How to find the column and row indices of values in a matrix using which function in R?

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

To find the row and column indices of values in a matrix, we cannot simply use which function because it returns the index based on sequence of the numbers in the matrix. For example, if we have a matrix M as below −1 2 3 4 1 6 7 8 1Now if we try to find the index using which(M==1) then it will return 1 5 9Because 1 is placed at 1, 5 and 9.Hence, we need to use arr.ind = TRUE so that the matrix can be read as an array by which function.ExampleConsider the below matrix −> M ...

Read More

How to find the number of distinct values in an R vector?

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

When we have repeated elements in an R vector and the vector size is large then we might want to know the distinct values in that vector. This will help us to understand the unique values we have in our vector, so that we can create the appropriate chart and perform the appropriate analysis using that vector. This can be done by using length function with unique.Examples> x1 x1Output[1] 2 5 5 3 2 4 3 3 1 4 5 4 5 3 3 1 1 2 5 1 3 2 4 1 3 1 5 4 2 5 5 ...

Read More

How to solve the simultaneous linear equations in R?

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

The data in simultaneous equations can be read as matrix and then we can solve those matrices to find the value of the variables. For example, if we have three equations as −x + y + z = 6 3x + 2y + 4z = 9 2x + 2y – 6z = 3then we will convert these equations into matrices and solve them using solve function in R.Example1> A AOutput   [, 1] [, 2] [, 3] [1, ] 1    1    2 [2, ] 3    2    4 [3, ] 2    3    -6> b bOutput[, 1] ...

Read More

How to remove a character in an R data frame column?

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

To remove a character in an R data frame column, we can use gsub() function which will replace the character with blank. For example, if we have a data frame called df that contains a character column say x which has a character ID in each value then it can be removed by using the command gsub("ID", "", as.character(df$x)).Example1Consider the below data frame −> x1 x2 df1 df1Output        x1  x2 1    Male1  8 2  Female1  4 3    Male1  9 4    Male1  2 5    Male1  7 6  Female1  5 7    Male1  3 8 ...

Read More

How to convert more than one column in R data frame to from integer to numeric in a single line code?

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

To convert columns of an R data frame from integer to numeric we can use lapply() function. For example, if we have a data frame df that contains all integer columns then we can use the code lapply(df,as.numeric) to convert all of the columns data type into numeric data type.Example1Consider the below data frame −set.seed(871) x1

Read More
Showing 1131–1140 of 1,958 articles
« Prev 1 112 113 114 115 116 196 Next »
Advertisements