Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Nizamuddin Siddiqui
Page 19 of 196
How to create a histogram with Y-axis values as count using ggplot2 in R?
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 MoreHow to subtract column values from column means in R data frame?
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 MoreHow to find the sum of numbers stored in character vector separated with a special character in R?
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 MoreHow to find the correlation matrix for rows of an R data frame?
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 MoreHow to create violin plot for categories with grey color palette using ggplot2 in R?
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 MoreHow to convert a list to JSON in R?
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 MoreHow to find the sum of non-missing values in an R data frame column?
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 MoreHow to find the column mean by excluding NA’s and if all values are NA then output NA in R data frame?
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 MoreHow to detect multicollinearity in categorical variables using R?
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 MoreHow to find the object size in R?
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