Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 43 of 196

How to recode factors in R?

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

Sometimes we have factor levels that can be combined or we want to group those levels in a single level. It is mostly done in situations where we have only one value for a particular factor level or there exists some theoretical concept that leads to combining the factor levels. For example, if we have a data frame called df that contains a factor column say x having four categories A, B, C, and D then they can be grouped into A and B as −df$x[df$x %in% c("A","B")]

Read More

What is the difference between class and typeof function in R?

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

The class function in R helps us to understand the type of object, for example the output of class for a data frame is integer and the typeof of the same object is list because data frames are stored as list in the memory but they are represented as a data frame. Check out the below examples with multiple type of objects to understand the differences.Example1x1

Read More

How to create transparent bar plot using ggplot2 in R?

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

To create transparent barplot using ggplot2, we can use alpha argument inside geom_bar function. For example, if we have a data frame called df that contains a categorical column say x and a numerical column say count then the bar plot with transparency can be created by using the command ggplot(df,aes(x,y))+geom_bar(alpha=0.1,stat="identity")ExampleConsider the below data frame −x

Read More

How to change the size of dots in dotplot created by using ggplot2 in R?

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

To change the size of dots in dotplot created by using ggplot2, we can use binwidth argument inside geom_dotplot. For example, if we have a data frame called df that contains a column x for which we want to create the dotplot then the plot with different size of dots can be created by using the command ggplot(df,aes(x))+geom_dotplot(binwidth=2).ExampleConsider the below data frame −x

Read More

How to find the opposite of %in% in R?

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

To find the opposite of %in%, we can use negation operator ! (exclamation sign). For example, if we have a data frame df that contains a column say x then to subset df by excluding some values (say 2, 3) we can use the command subset(df,!(x %in% c(2,3))).Example1Consider the below data frame −x1

Read More

How to create duplicate matrices and merge them together in R?

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

To create duplicate matrices, we can use replicate function that will repeat the original matrix and if we want to merge those matrices together then we can use rbind with do.call. For example, if we have a matrix called M then creation of it’s one duplicate and merging them together can be done using the command −do.call(rbind,replicate(2,M,simplify=FALSE))ExampleM

Read More

How to find the row-wise mode of a matrix in R?

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

There is no in-built function to find the mode in R, hence we need to create one and then apply it to the rows of the matrix. The function for mode is created as follows −mode M1 M1Output     [,1] [,2] [,3] [,4] [,5] [1,]  2    2    1    2   2 [2,]  2    2    2    2   1 [3,]  2    2    1    1   1 [4,]  2    1    1    1   1 [5,]  2    1    1    2   2> apply(M1,1,mode)Output[1] 2 2 1 1 2Example2> M2 M2Output     [,1] [,2] [,3] [,4] [,5] [1,]  1    1    2    2    1 [2,]  2    1    1    2    1 [3,]  2    2    1    1    1 [4,]  2    1    1    2    2 [5,]  2    1    1    2    2 [6,]  1    2    1    1    2 [7,]  1    1    2    1    2 [8,]  2    2    1    2    1 [9,]  2    1    1    2    2 [10,] 1    1    2    2    2 [11,] 1    1    2    1    2 [12,] 1    2    2    2    1 [13,] 2    2    2    2    1 [14,] 2    1    2    2    1 [15,] 1    2    1    1    2 [16,] 2    2    1    2    1 [17,] 2    2    1    1    1 [18,] 2    1    1    2    1 [19,] 1    1    1    2    1 [20,] 2    1    1    2    2> apply(M2,1,mode)Output[1] 1 1 1 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 1 2Example3> M3 M3Output     [,1] [,2] [,3] [,4] [,5] [1,]  1    3    3    2    1 [2,]  2    3    1    2    2 [3,]  2    2    3    3    1 [4,]  1    3    1    3    2 [5,]  3    1    2    1    2 [6,]  2    3    1    1    1 [7,]  2    2    2    3    1 [8,]  1    2    2    2    2 [9,]  2    1    2    1    2 [10,] 1    3    1    2    1 [11,] 2    1    3    1    1 [12,] 1    1    3    2    2 [13,] 2    1    1    1    2 [14,] 2    1    3    3    2 [15,] 1    2    3    1    2 [16,] 1    2    1    2    1 [17,] 3    1    1    3    2 [18,] 3    3    3    3    1 [19,] 3    2    3    1    1 [20,] 3    3    2    2    1> apply(M3,1,mode)Output[1] 1 2 2 1 1 1 2 2 2 1 1 1 1 2 1 1 1 3 1 2Example4> M4 M4Output      [,1] [,2] [,3] [,4] [,5] [1,]  10    10   9    10   9 [2,]  9     9    10   9    9 [3,]  9     9    9    10   10 [4,]  10    9    9    10   10 [5,]  10    10   9    10   9 [6,]  10    10   9    10   10 [7,]  9     9    9    10   9 [8,]  9     10   9    10   9 [9,]  9     9    9    9    9 [10,] 9     10   9    10   9 [11,] 10    10   9    9    9 [12,] 9     9    9    9    9 [13,] 10    10   10   9 10 [14,] 10    9    10   10 10 [15,] 9     10   9    10 9 [16,] 9     10   9    10 9 [17,] 9     10   10   9 10 [18,] 9     9    9    9 10 [19,] 10    9    9    10 9 [20,] 10    9    9    10 9> apply(M4,1,mode)Output[1] 10 9 9 10 10 10 9 9 9 9 9 9 10 10 9 9 10 9 9 9

Read More

How to find the percentage for frequencies stored in a vector with two decimal places in R?

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

To find the percentage for frequencies stored in a vector with two decimal places can be done with the help of sum function and round function. For example, if we have a vector of frequencies say x then the percentage of these frequencies can be found by using the command round((x/sum(x))*100,2). Check out the below examples to understand how it works.Example1Frequency1

Read More

How to find the frequency table for factor columns in an R data frame?

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

If we have factor columns in an R data frame then we want to find the frequency of each factor level for all the factor columns. This can be done with the help of sapply function with table function. For example, if we have a data frame called df that contains some factor columns then the frequency table for factor columns can be created by using the command sapply(df, table).Example1Consider the below data frame −> x1 x2 df1 df1Output   x1 x2 1  D  a 2  D  b 3  D  c 4  D  b 5  D  c 6  C  a 7 ...

Read More

How to set the text position using geom_text in R?

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

To set the text position using geom_text, we can use the value for the X-axis and Y-axis with appropriate positions. We need to make sure that the values we set for both the axes do not lie within the data otherwise the text will be printed on the plot we want to draw and it will become less attractiveExampleConsider the below data frame −x

Read More
Showing 421–430 of 1,958 articles
« Prev 1 41 42 43 44 45 196 Next »
Advertisements