Programming Articles - Page 877 of 3366

How to change the background color of base R plot region?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 07:12:26

1K+ Views

To change the background color of base R plot region, we can follow the below steps −First of all, create a plot in base R to understand the difference.Then, use par function with bg argument where you can put color name and then create the same plot.ExampleCreate the plotLet’s create a barplot in base R as shown below −x

How to convert values greater than a threshold into 1 in column of a data.table object in R?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 07:09:35

182 Views

To convert values greater than a threshold into 1 in data.table object in R data frame, we can follow the below steps −First of all, create a data.table object.Then, use ifelse function to convert values greater than a threshold into 1.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) x

How to find the percent of NA’s in data.table object rows in R?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 07:08:11

216 Views

To find the percent of NAs in each row of a data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, use rowSums function and ncol function along with apply function to find the percent of NAs in each row of the data.table object.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) x1

How to remove rows in R data frame that contains a specific number?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 07:03:45

2K+ Views

To remove rows in R data frame that contains a specific number, we can follow the below steps −First of all, create a data frame.Then, use single square subsetting with apply function to remove rows that contains a specific number.ExampleCreate the data frameLet’s create a data frame as shown below −x

How to display legend in base R with different colors?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 07:01:24

2K+ Views

To display legend in base R with different colors, we can follow the below steps −First of all, create a plot using plot function.Then, use legend function legend argument and col argument to display legend with different colors.ExampleCreate the plotLet’s create a plot of a vector x using plot function −x

How to repeat column values of a data.table object in R by number of values in another column?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:58:38

609 Views

To repeat column values of a data.table object by values in another column, we can follow the below steps −First of all, create a data.table object.Then, use rep function along with cbind function to repeat column values in the matrix by values in another column.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) x

How to find the mean of a column summarized by other column names and common values in those columns in R data frame?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:55:54

105 Views

To find the mean of a column summarized by other column names and common values in those columns in R data frame, we can follow the below steps −First of all, create a data frame.Then, melt the data frame using melt function from reshape2 package.After that, use dcast function to find the mean of a column summarized by other column names and common values in those columns.ExampleCreate the data frameLet’s create a data frame as shown below −S.No

How to decompose a time series with trend and seasonal components using loess method in R?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:49:57

479 Views

To decompose a time series with trend and seasonal components using loess method in R, we can follow the below steps −First of all, create a time series object.Then, use stl function to decompose the time series with trend and seasonal components.ExampleCreate the time series objectLet’s create a time series object using ts function −x

How to display text in bar plot in the middle using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:46:24

4K+ Views

To display text in bar plot in the middle using ggplot2 in R, we can follow the below steps −First of all, create a data frame.Then, use ggplot function and geom_bar function to create the bar plot along with geom_text function to display the text in the middleExampleCreate the data frameLet’s create a data frame as shown below −x

How to find the percentage of zeros in each column of a data.table object in R?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:43:55

265 Views

To find the percentage of zeros in each column of a data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, use colSums function along with nrow function to find the percentage of zeros in each column.Example 1Create the data.table objectLet’s create a data.table object as shown below −library(data.table) y1

Advertisements