Nizamuddin Siddiqui has Published 2307 Articles

How to create a column of difference in data frames stored in R list?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Nov-2021 07:37:26

78 Views

To create a column of difference in data frames stored in R list, we can follow the below steps −First of all, create a list of data frames.Then, use lapply function to create a column of difference in data frames stored in the list.ExampleCreate the list of data framesUsing data.frame ... Read More

How to create a matrix with only one row in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Nov-2021 07:36:31

1K+ Views

To create a matrix with only one row in R, we can set the nrow argument of matrix function to 1.For example, if we want to create a matrix say M with only one row then it can be done by using the command given below −M

How to combine two rows in data.table object in R by addition?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Nov-2021 07:34:16

846 Views

To combine two rows in data.table object in R by addition, we can follow the below steps −First of all, create a data.table object.Then, using plus sign (+) to add two rows and store the addition in one of the rows.After that, remove the row that is not required by ... Read More

How to find the groupwise mean and groupwise sum at the same time in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Nov-2021 07:33:44

107 Views

To find the groupwise mean and groupwise sum at the same time, we can first convert the data frame into a data.table object and then apply the sum function and mean function for data.table object groups as shown in the below examples.Example 1Following snippet creates a sample data frame −GroupRead More

How to minus every element of a vector with every element of another vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Nov-2021 07:30:34

433 Views

To minus every element of a vector with every element of another vector, we can use outer function by defining the subtraction sign.For example, if we have two vectors say x and y and we want to minus every element in x from every element in y then we can ... Read More

How to create a column of total in data frames stored in R list?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Nov-2021 07:27:08

67 Views

To create a column of total in data frames stored in R list, we can follow the below steps −First of all, create a list of data frames.Then, use lapply function to create a column of total in data frames stored in the list.ExampleCreate the list of data framesUsing data.frame ... Read More

How to change the name of data frames stored in an R list?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Nov-2021 07:21:33

984 Views

To change the name of data frames stored in an R list, we can follow the below steps −First of all, create a list of data frames.Then, use names function to change the name of data frames.ExampleCreate the list of data framesUsing data.frame function to create data frames and list ... Read More

How to find all combinations of a vector elements without space in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Nov-2021 07:21:02

95 Views

When we want to find the combinations of a vector elements, we can use combn function with size of the combination say 2 for pairs but the result gives space between the values. If we do not want to get the combinations with space then combn function will be used ... Read More

How to find the cumulative sum for each row in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Nov-2021 07:20:02

805 Views

To find the cumulative sum for each row in an R data frame, we would need to read the data frame as a data.table object and then Reduce function will be used with accumulate argument.For Example, if we have a data frame called df and we want to find the ... Read More

How to find the frequency of particular value in rows of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Nov-2021 07:18:16

898 Views

To find the frequency of particular value in rows of an R data frame, we can use mutate function of dplyr package along with rowSums function.For example, if we have a data frame called df then we can find the number of 5’s in each row of df by using ... Read More

Advertisements