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
-
Economics & Finance
Articles by Nizamuddin Siddiqui
Page 27 of 196
How to perform group-wise linear regression for a data frame in R?
The group−wise linear regression means creating regression model for group levels. For example, if we have a dependent variable y and the independent variable x also a grouping variable G that divides the combination of x and y into multiple groups then we can create a linear regression model for each of the group. In R, we can convert data frame to data.table object, this will help us to create the regression models easily.Exampledf2[,as.list(coef(lm(Salary~Ratings))),by=Class]OutputClass (Intercept) Ratings 1: I 31894.13 194.9152 2: III 35270.10 663.4089 3: II 40405.42 -1087.9103
Read MoreHow to find the total of frequency based on the values of a factor column in R?
Often, we have duplicate values in a factor column that means a factor column has many levels and each of these levels occur many times. In this situation, if we have a frequency column then we want to find the total of that frequency based on the values of a factor column and this can be done by using aggregate function.Example> Metal Quantity df2 head(df2, 10) Metal Quantity 1 Iron 43 2 Nickel 33 3 Lead 25 4 Zinc 24 5 Tin 27 6 Sodium 34 7 Silver ...
Read MoreHow to create a step histogram using ggplot2 in R?
To create a step histogram using ggplot2, we can use geom="step" argument inside stat_bin function. For example, if we have a data frame that contains a single column then the step histogram can be created using the command − ggplot(df,aes(x))+stat_bin(geom="step",bins=30)Examplelibrary(ggplot2) ggplot(df,aes(x))+stat_bin(geom="step",bins=30)Output
Read MoreHow to display star for significance in base R boxplot?
To display the star for significance in a base R boxplot, we can use text function. The text function will be helpful in defining the star sign (that is asterisk or *). If the significance is high then three stars are used and the significance is low then a single star is used. We need to use the appropriate position using x and y values.Exampletext(x=1,y=max(df$y[df$x==1]),"***",pos=3,cex=1.5)Output
Read MoreHow to divide the data frame rows in R by row standard deviation?
To divide the data frame row values by row standard deviation in R, we can follow the below steps −First of all, create a data frame.Then, use apply function to divide the data frame row values by row standard deviation.Creating the data frameLet's create a data frame as shown below −> x y df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) − x y 1 1.48 0.86 2 -0.14 -0.58 3 -0.25 1.22 4 0.18 0.25 5 0.50 0.68 6 -1.34 -0.21 ...
Read MoreHow to extract the factor levels from factor column in an R data frame?
To extract the factor levels from factor column, we can simply use levels function. For example, if we have a data frame called df that contains a factor column defined with x then the levels of factor levels in x can be extracted by using the command levels(df$x). This extraction is helpful if we have a large number of levels.Example1x2
Read MoreHow to create bar chart based on two groups in an R data frame?
To create a bar chart based on two groups, we can use geom_bar function of ggplot2 package with position argument that defines the position of the groups. For example, if we have a data frame called df that contains two categorical variable x1 and x2 and the one response variable y then the bar chart can be created by using the below command −ggplot(df,aes(x1,y,fill=x2))+geom_bar(position=position_dodge(),stat="identity")Examplelibrary(ggplot2) ggplot(df,aes(Age_Group,Y,fill=Gender))+geom_bar(position=position_dodge(),stat="identity")Output
Read MoreHow to find the row and column position of a value as vector in an R matrix?
To find the row and column position of a value as vector in an R matrix, we can follow the below steps −First of all, create a matrix.Then, find the row and column position of a particular value using which function and reading the output with as.vector function.Example 1Create a matrixLet's create a matrix as shown below −M1
Read MoreHow to divide data frame rows in R by row maximum?
To divide the data frame row values by row maximum in R, we can follow the below steps −First of all, create a data frame.Then, use apply function to divide the data frame row values by row maximum.Create the data frameLet's create a data frame as shown below −x
Read MoreHow to print string vectors vertically in R?
To print string vectors vertically in R, we can follow the below steps −First of all, create a vector.Then, use cat function to print the vector vertically.Example 1 Let's create a vector as shown below −Alphabets
Read More