Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 155 of 196

How to change a text value in an R data frame?

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

To change a text value in an R data frame, we can simply use replace function.For Example, if we have a data frame called df that contains a column say Names and one of the names say Raj is misspelled as Raaj then we can replace Raaj with Raj by using the command given below −df$Names

Read More

How to find mathematical set using a data frame column in R?

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

A mathematical set is a collection of unique elements or a collection of elements that are different from each other. If we want to find a mathematical set using a data frame column then we can simply use unique function.For Example, if we have a data frame called df that contains a column say X then we can find the mathematical set using X with the help of below command −unique(df$X)Example 1Following snippet creates a sample data frame −x

Read More

How to change the color of gridlines of a ggplot2 graph in R?

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

To change the color of gridlines of a ggplot2 graph in R, we can use theme function with panel.grid.major and panel.grid.minor arguments where we can set the minor and major gridlines color of the plot panel to desired color.To understand how it can be done, check out the below Example.ExampleFollowing snippet creates a sample data frame −x

Read More

How to change the plot border color of a ggplot2 graph in R?

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

To change the plot border color of a ggplot2 graph in R, we can use theme function with panel.background argument where we can set the border of the plot panel using element_rect to desired color.To understand how it can be done, check out the below Example.ExampleFollowing snippet creates a sample data frame −x

Read More

How to create horizontal line in xyplot in R?

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

To create horizontal line in xyplot, we can use abline function.For Example, if we have a data frame called df that contains two columns say X and Y and we want to create a scatterplot between X and Y using xyplot with a horizontal line at Y = 2 then we can use the command given below −xyplot(Y~X,df,abline=c(h=2))ExampleFollowing snippet creates a sample data frame −x

Read More

R Programming to find the column name for row maximum in a data.table object.

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

If we have a data.table object and we want to find the column name for row maximum then we can use max.col function.For Example, if we have a data.table object called DT then we can find the column name for row maximum by using the below command −DT[,names(.SD)[max.col(.SD,ties.method="first")]]Example 1Following snippet creates a sample data frame −x1

Read More

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 631 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 540 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
Showing 1541–1550 of 1,958 articles
« Prev 1 153 154 155 156 157 196 Next »
Advertisements