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 140 of 196
How to change the X-axis labels for boxplots created by using boxplot function in R?
When we create boxplots for multiple categories in R using boxplot function, by default the X-axis labels are represented by numbers. But we might want to express the categories by their name. In this situation, we can use names argument along with the boxplot function.Consider the below vectors that represent different categories and create the boxplot for these categories −ExampleClass1
Read MoreHow to change the color of bars in histogram for values that are greater than 0 or less than 0 in R?
Although, the histogram represents the distribution of a complete set of values but we might want to visualize that histogram based on the division of some threshold value. For example, we might want to visualize the histogram with different bars that have values greater than 1 or less than 1. This will help us to understand the distribution of the values in whole data set that lies above or below certain value. For this purpose, we can simply use hist function with col argument to change the color of the values that are greater than or less than a fixed ...
Read MoreHow to find residual variance of a linear regression model in R?
The residual variance is the variance of the values that are calculated by finding the distance between regression line and the actual points, this distance is actually called the residual. Suppose we have a linear regression model named as Model then finding the residual variance can be done as (summary(Model)$sigma)**2.Examplex1
Read MoreHow to display the values of two columns of an R data frame separately in a plot?
In general, the scatterplot is used to visualize the relationship between two columns of an R data frame but if we want to display the two columns separately not as a pair then we need to use matplot function. This function will create a plot for all the values in the two columns and represent them by their column number.Consider the below data frame −Example Live Demoset.seed(222) x
Read MoreHow to standardize matrix elements in R?
The standardization is the process of converting a value to another value so that the mean of the set of values from which the original value was taken becomes zero and the standard deviation becomes one. To standardize matrix elements, we can use data.Normalization function of clusterSim package but we need to make sure that we set the type argument to n1 because that corresponds to standardization with mean zero and standard deviation 1.Loading clusterSim package −library("clusterSim")Example Live DemoM1
Read MoreHow to change a data frame with comma separated values in columns to multiple columns in R?
Mostly, we need to import the data from an outside source in R environment for analysis and these data can be recorded as comma separated values that represent rows. If we want to create the columns for the comma separated values then cSplit function of splitstackshape package can be used. In the below example, we have created a data frame with comma separated values then splitting those values as single value in each column.Consider the below data frame −Example Live Demodf=data.frame(x=apply(matrix(rpois(200, 10), 20, 10), 1, paste, collapse=", ")) dfoutputx 1 8, 12, 7, 12, 10, 8, 11, 6, 8, 7 2 ...
Read MoreHow to add a mathematical expression in axis label in a plot created by using plot function in R?
When we create a plot using plot function in R, the axes titles are either chosen by R automatically based on the vectors passed through the function or we can use ylab or xlab for particular axes. To add a mathematical expression in an axis label, we can use title function with expression function to define the mathematical expression.Consider the below vectors and create scatterplot between the two −Exampleset.seed(111) x
Read MoreHow to create a black and white word cloud in R?
According to Google, a word cloud is an image composed of words used in a particular text or subject, in which the size of each word indicates its frequency or importance. In R, we can create word cloud by using wordcloud function of wordcloud package. So, we have the same name of the function as the package, thus we should not get confused by it.Loading wordcloud package and creating a wordcloud −library("wordcloud") x
Read MoreHow to convert the repeated elements of strings in a vector to unique elements in R?
When we have repeated elements of strings and we want to use them as factor levels then it is okay but if we want to treat them individually then it is better to make each value a unique element. To do this, we can use make.unique function. For example, if we have a vector x that contains repeated string values then to make them unique, we can use make.unique(x).Example Live Demox1
Read MoreHow to subtract one data frame from another in R?
If we have two data frames with same number of columns of same data type and equal number of rows then we might want to find the difference between the corresponding values of the data frames. To do this, we simply need to use minus sign. For example, if we have data-frames df1 and df2 then the subtraction can be found as df1-df2.Consider the below data frame −Example Live Demox1
Read More