Nizamuddin Siddiqui has Published 2307 Articles

How to find the number of zeros in each column of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 07:12:28

8K+ Views

To find the number of zeros in each column of an R data frame, we can follow the below steps −First of all, create a data frame.Then, use colSums function to find the number of zeros in each column.Example 1Create the data frameLet’s create a data frame as shown below ... Read More

How to remove rows in data.table object in R that contains a specific number?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 07:09:42

193 Views

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

How to change the sign of even number rows in single column matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 07:06:54

107 Views

To change the sign of even number rows in R matrix, we can follow the below steps −First of all, create a matrix.Then, use vector multiplication with 1 and minus 1 to change the sign of even number rows.ExampleCreate the matrixLet’s create a matrix as shown below −M

How to multiply corresponding row values in a matrix with single row matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 07:04:33

365 Views

To multiply row values in a matrix having multiple rows with single row matrix in R, we can follow the below steps −First of all, create a matrix with multiple rows and a matrix with single row.Then, use mapply function to multiply row values in those matrices.ExampleCreate the first matrixLet’s ... Read More

How to subset a data.table object in R by ignoring a value in one of the columns?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 06:57:38

91 Views

To subset a data.table object in R by ignoring a value in one of the columns, we can follow the below steps −First of all, create a data.table object.Then, use single square brackets to subset the data.table object by ignoring a value in one of the columns.ExampleCreate the data.table objectLet’s ... Read More

Check which column names contain a specific string in R data frame.

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 06:57:31

4K+ Views

If we have a data frame that contains columns having names with some commong strings then we might want to find those column names. For this purpose, we can use grepl function for subsetting along with colnames function.Check out the Examples given below to understand how it can be done.Example ... Read More

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

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 06:55:57

913 Views

To find the percentage of each category in a data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, use summarise function of dplyr package after grouping along with n and nrow.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) ... Read More

How to find the number of zeros in each row of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 06:52:06

949 Views

To find the number of zeros in each row of an R data frame, we can follow the below steps −First of all, create a data frame.Then, use rowSums function to find the number of zeros in each row of the data frame.ExampleCreate the data frameLet’s create a data frame ... Read More

How to find the number of columns where all row values are equal in R matrix?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 06:49:23

262 Views

To find the number of columns where all row values are equal in R matrix, we can follow the below steps −First of all, create a matrix.Then, use sum function along with length and apply function to find the number of columns where all row values are equal.Example 1Create the ... Read More

How to create pivot table with sum for data stored in R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 06:46:20

581 Views

To create pivot table with sum for data stored in R data frame, we can follow the below steps −First of all, create a data frame with two categorical and one numerical column.Then, use dcast function from reshape2 package to create pivot table for the data stored in data frame.ExampleCreate ... Read More

Advertisements