Found 2038 Articles for R Programming

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

459 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

41 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

318 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

3K+ 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

189 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

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

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

446 Views

To remove rows in R matrix that contains a specific number, we can follow the below steps −First of all, create a matrix.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 −M

How to convert values greater than a threshold into 1 in R data frame column?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:36:01

2K+ Views

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

How to subset R data frame rows if at least one or more values matches?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:34:14

300 Views

To subset R data frame rows if at least one or more values matches, we can follow the below steps −First of all, create a data frame.Then, use rowSums function along with sapply function and values for match to subset the data frame rows if at least one or more values matches.ExampleCreate the data frameLet’s create a data frame as shown below −x

How to repeat column values in R data frame by values in another column?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:31:31

2K+ Views

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

How to standardize selected columns in R data frame?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:28:17

2K+ Views

To standardize selected columns in R data frame, we can follow the below steps −First of all, create a data frame.Then, use scale function with subsetting to standardize selected columns.ExampleCreate the data frameLet’s create a data frame as shown below −v1

Advertisements