Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 41 of 196

How to find the row sums if NA exists in the R data frame?

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

To find the row sums if NA exists in the R data frame, we can use rowSums function and set the na.rm argument to TRUE and this argument will remove NA values before calculating the row sums.For Example, if we have a data frame called df that contains some NA values then we can find the row sums by using the below command −df$Row_Sums

Read More

How to add zero before a vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 600 Views

To add zero before a vector in R, we can simply use rep function and provide the number times we want to have zero in the vector.For Example, if we have a vector called X that contains three values say 1, 2, 3 and we want to add three zeros before this vector then we can use the command as given below −X

Read More

Fill bars in a base R barplot with colors based on frequency.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 03-Nov-2021 518 Views

Suppose we have a vector that contains only frequencies and we want to create a bar chart in base R using these frequencies with color of bars based on frequencies, therefore, we can use barplot function and providing the color of the bars with as shown in the below ExamplesThe function is as follows −heat.colors functionExample 1To fill the bars in a base R barplot with colours based on frequency, use the command given below −Frequency_1

Read More

How to create a circle filled with a color in R?

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

We can create a circle in R by using draw.circle function of plotrix package and default color of the circle is white. If we want to change the color of a circle then we can use col argument and pass the desired colors.For Example, if we want to create a blue colored circle then we can use the command given below −draw.circle(5, 5, 2, col="blue")Check out the below Example to understand how it works.ExampleTo create a circle filled with a colour, use the command given below −plot(1:10, type="n") OutputIf you execute the above command, it generates the following Output −To ...

Read More

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 158 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 825 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 494 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
Showing 401–410 of 1,958 articles
« Prev 1 39 40 41 42 43 196 Next »
Advertisements