Convert Values Greater Than Threshold into 1 in Data Table Column in R

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

193 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

Find Percent of NA's in Data Table Object Rows in R

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

229 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

Remove Rows in R Data Frame Containing 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

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

Repeat Column Values of a Data Table Object in R

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

621 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

Find Mean of a Column Summarized by Other Columns in R Data Frame

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

117 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

Decompose Time Series Using LOESS Method in R

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

496 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

Display Text in Bar Plot 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

Find Percentage of Zeros in Each Column of Data Table in R

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

272 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

Plot Matrix Elements Using corrplot in R

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:41:52

3K+ Views

To create a plot of matrix elements with the help of corrplot function, we would need to set is.corr argument to FALSE so that the matrix values will be plotted in the diagram, otherwise, the corrplot function requires correlation matrix instead of a matrix hence there will be an error as shown in the Example below.ExampleConsider the matrix given below −M

Advertisements