Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 42 of 196

Remove rows from a data frame that exists in another data frame in R.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 6K+ Views

To remove rows from a data frame that exists in another data frame, we can use subsetting with single square brackets. This removal will help us to find the unique rows in the data frame based on the column of another data frame.Check out the below Examples to understand how it can be done.Example 1Following snippet creates a sample data frame −x

Read More

Add values in sequence to the previous value with a constant.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 620 Views

To add values in sequence to the previous value with a constant, we can find the cumulative sum of values and add the constant to the Output.For Example, if we have a vector called X and we want to add values in X in sequence to the previous value with a constant say 10 then we can use the command given below −10+cumsum(X)Example 1Following snippet creates a sample data frame −x1

Read More

Create cross tabulation for three categorical columns in an R data frame.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 2K+ Views

To create cross tabulation for three categorical columns, we can use xtabs function. The xtabs function will create contingency table for each category in two columns and each contingency table will be created for the category in the third column.Check out the below Examples to understand how it can be done.Example 1Following snippet creates a sample data frame −df1

Read More

R Programing to change the name of column variable and row variable in xtab table.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 526 Views

To change the name of column variable and row variable in xtab table, we can use setNames function.For Example, if we have a xtab table called XTAB and we want to change the column variable name C and row variable name R then we can use the below command −dimnames(XTAB)

Read More

How to create confusion matrix for a rpart model in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 1K+ Views

To create confusion matrix for a rpart model, we first need to find the predicted values then the table of predicted values and the response variable in the original data can be created, which will be the confusion matrix for the model.For Example, if we have a vector of predicted values say P and original values in data frame df$O then the confusion matrix can be created by using the following command −table(P, df$O)Check out the below Examples to understand how it can be done.Example 1Following snippet creates a sample data frame −Dep_Var1

Read More

Find the product of vector elements in pairs moving forward in R.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 233 Views

To find the product of vector elements in pairs moving forward, we can use prod function along with combn function.For Example, if we have a vector called V and we want to find the product of elements of V in pairs moving forward then we can use the following command −combn(V,2,prod)Example 1Following snippet creates a sample data frame −x1

Read More

How to create bar plot using ggplot2 with structure data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 1K+ Views

To create bar plot using ggplot2 with structure data, we need to set the stat argument of geom_bar function to identity. This is same for the regular data frame.For example, if we have a structured data frame called df that contains a column X for categories and a numerical column say Y for frequency then we can the bar plot for this data by using the below given command −ggplot(df,aes(X,Y))+geom_bar(stat="identity")ExampleFollowing snippet creates a sample data frame −df

Read More

How to display data frame name in ggplot2 graph title in R?\\n

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 657 Views

To display data frame name in ggplot2 graph title, we can use ggtitle function and pass the name of the data frame.For example, if we have a data frame called df that contains two columns say x and y and we can create a point chart between x and y then the plot with data frame name as title can be created by using the below mentioned command −ggplot(df,aes(x,y))+geom_point()+ggtitle("df")ExampleFollowing snippet creates a sample data frame −x

Read More

How to create a colored frame for ggplot2 graph in R?\\n

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 328 Views

To create a colored frame for ggplot2 graph, we can use theme function and set the plot.background argument to different color for rectangular element.For example, if we have a data frame called df that contains two columns say X and Y then we can create point chart between X and Y with blue colored frame of the plot using the below mentioned command −ggplot(df,aes(X,Y))+geom_point()+theme(plot.background=element_rect(colour="blue",size=3))ExampleFollowing snippet creates a sample data frame −x

Read More

How to add title to regression model using stargazer in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 1K+ Views

To add title to regression model using stargazer, we can use title argument inside stargazer function.For example, if we have a model called Reg_Model with Output as text then the title to this model using stargazer can be added by using the below mentioned command −stargazer(Reg_Model,type="text",title="Regression Model between x and y")Example 1Following snippet creates a sample data frame −x

Read More
Showing 411–420 of 1,958 articles
« Prev 1 40 41 42 43 44 196 Next »
Advertisements