Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 135 of 196

How to write text outside plot using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 11K+ Views

To write text outside plot using ggplot2, we can use annotate function and coord_cartesian function. The annotate function will define the text value and the coord_cartesian function will define the position of the text outside the plot area.Check out the below example to understand how it works.ExampleFollowing snippet creates a sample data frame −x

Read More

Find the mean of multiple columns based on multiple grouping columns in R data frame.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 5K+ Views

To find the mean of multiple columns based on multiple grouping columns in R data frame, we can use summarise_at function with mean function.For Example, if we have a data frame called df that contains two grouping columns say G1 and G2 and two numerical columns say Num1 and Num2 then we can find the mean of Num1 and Num2 based on G1 and G2 by using the below mentioned command −df%%group_by(G1,G2)%%summarise_at(vars("Num1","Num2"),mean)Example 1Following snippet creates a sample data frame −Gender

Read More

How to cut a data frame column with minimum value in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 593 Views

To cut a data frame column with minimum value, we need to specify the minimum value withing cut function with the help of min function and set the include.lowest argument to TRUE. We can also specify the maximum value so that the maximum value is also taken into account while cutting the column.Example 1Following snippet creates a sample data frame −x

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 179 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 function to create data frames and list function to create the list of those data frames −df1

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 2K+ 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

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 1K+ 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 subsetting with single square brackets.ExampleCreate the data.table objectLet’s create a data.table object as shown below: −library(data.table) x

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 244 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 −Group

Read 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 600 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 use the below mentioned command −outer(x,y,`-`)Example 1Following snippet creates a sample vector −x1

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 184 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 function to create data frames and list function to create the list of those data frames −df1

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 2K+ 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 function to create the list of those data frames −df1

Read More
Showing 1341–1350 of 1,958 articles
« Prev 1 133 134 135 136 137 196 Next »
Advertisements