Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 19 of 196

How to create a histogram with Y-axis values as count using ggplot2 in R?

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

To create a histogram with Y-axis values as count using ggplot2 in R, we can follow the below steps −First of all, create a data frame.Then, use geom_histogram function of ggplot2 package with aes to create the histogram with Y-axis values as count.Create the data frameLet's create a data frame as shown below −> df head(df, 20)On executing, the above script generates the below output(this output will vary on your system due to randomization) −          x 1    -0.008015477 2    -0.981227322 3     1.144050354 4     0.207177231 5     0.179782914 6   ...

Read More

How to subtract column values from column means in R data frame?

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

To subtract column values from column means in R data frame, we can follow the below steps −First of all, create a data frame.Then, find the column means using colMeans function.After that, subtract column values from column means.Creating the data frameLet's create a data frame as shown below −> x1 x2 x3 df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −   x1  x2  x3 1  54  73  57 2  79  52  92 3  87  51  47 4  13  12   1 5  70  90  19 6  15  99   ...

Read More

How to find the sum of numbers stored in character vector separated with a special character in R?

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

To find the sum of numbers stored in character vector separated with a special character in R, we can follow the below steps −First of all, create a vector having numbers stored in character vector separated with a special character.Then, use sapply and strsplit function to find the sum of numbers.Example1Create a vector with numbers stored in character vector separated with hyphen −> x1 x1On executing, the above script generates the below output(this output will vary on your system due to randomization) − [1] "11-2-15-19-10"   "11-2-15-19-10"    "13-12-75-29-18"  "15-25-52-91-10"  [5] "15-25-52-91-10"  "17-27-55-91-100"  "13-12-75-29-18"  "15-25-52-91-10"  [9] "13-12-75-29-18"  "10-4-5-19-10"     "17-27-55-91-100" ...

Read More

How to find the correlation matrix for rows of an R data frame?

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

To find the correlation matrix for rows of an R data frame, we can follow the below steps −First of all, create a data frame.Then, use cor function with transposed data frame to find the correlation matrix for rows.Example1Let's create a data frame as shown below −> x1 x2 x3 x4 x5 df1 df1On executing, the above script generates the below output(this output will vary on your system due to randomization) −      x1          x2       x3          x4       x5 1 0.23392099 -0.0919377 0.4623323 -0.5209734 0.1769501 2 ...

Read More

How to create violin plot for categories with grey color palette using ggplot2 in R?

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

To create violin plot for categories with grey color palette using ggplot2, we can follow the below steps −First of all, create a data frame.Then, create the violin plot for categories with default color of violins.Create the violin plot for categories with color of violins in grey palette.Creating the data frameLet's create a data frame as shown below −> Group Score df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −     Group  Score 1   Second   405 2    Third   947 3    First    78 4 ...

Read More

How to convert a list to JSON in R?

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

To convert a list to JSON, we can use toJSON function of jsonlite package. For example, if we have a list called LIST then it can be converted to a JSON by using the command toJSON(LIST,pretty=TRUE,auto_unbox=TRUE). We need to make sure that the package jsonlite is loaded in R environment otherwise the command won’t work.ExampleList

Read More

How to find the sum of non-missing values in an R data frame column?

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

To find the sum of non-missing values in an R data frame column, we can simply use sum function and set the na.rm to TRUE. For example, if we have a data frame called df that contains a column say x which has some missing values then the sum of the non-missing values can be found by using the command sum(df$x,na.rm=TRUE).Example1Consider the below data frame −x1

Read More

How to find the column mean by excluding NA’s and if all values are NA then output NA in R data frame?

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

To find the column mean by excluding NA’s can be easily done by using na,rm but if we want to have NA if all the values are NA then it won’t be that straight forward. Therefore, in such situation, we can use ifelse function and return the output as NA if all the values are NA as shown in the below examples.Example1Consider the below data frame −x1

Read More

How to detect multicollinearity in categorical variables using R?

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

The multicollinearity is the term is related to numerical variables. It means that independent variables are linearly correlated to each other and they are numerical in nature. The categorical variables are either ordinal or nominal in nature hence we cannot say that they can be linearly correlated.ExampleConsider the below data frame −x

Read More

How to find the object size in R?

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

To find the object size in R, we can use object.size function. For example, if we have a data frame called df then the size of df can be found by using the command object.size(df). Similarly, if we have a vector say x then it’s size can be found using object.size(x) and for a matrix M it can be object.size(M).Example1Consider the below data frame −x

Read More
Showing 181–190 of 1,958 articles
« Prev 1 17 18 19 20 21 196 Next »
Advertisements