R Programming Articles

Page 96 of 174

How to find the mean of all matrices stored in an R list?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 478 Views

To find the mean of all matrices stored in an R list, we can use sapply function along with mean function. For example, if we have a list called LIST that contains some matrices then the mean of each matrix can be found by using the command given below −sapply(LIST,mean)Check out the below given example to understand how it works.ExampleFollowing snippet creates a list of matrices −M1

Read More

How to update single value in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 4K+ Views

To update single value in an R data frame, we can use row and column indices with single square brackets.For example, if we have a data frame called df that contains two columns and ten rows and if we want to change the fifth value in second column to 10 then we can use the command given below −df[5,2]

Read More

How to find the coordinate of a value in an R matrix?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 2K+ Views

The coordinate of a value in an R matrix is the row and column intersection that is the row and column index for that particular value. This can be found by using which function.For example, if we have a matrix called M that contains value starting from 1 to 20 then we can find the coordinate of value 5 by using the command given below − which(M==5,arr.ind=TRUE)ExampleFollowing snippet creates a matrix −M1

Read More

How to fill missing values after merging the data frames with another value than NA in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Nov-2021 2K+ Views

To fill missing values after merging the data frames with another value than NA in R, we can follow the below steps −First of all, create two data frames.Then, merge the data frames by a common column between the two.After that, replace the NAs with another value.ExampleCreate the first data frameLet’s create a data frame as shown below −ID

Read More

How to use top_n function from dplyr to extract rows based on one column ordered in descending order in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Nov-2021 913 Views

To use top_n function from dplyr to extract rows based on one column ordered indescending order in R, we can follow the below steps −First of all, create a data frame.Then, use top_n function dplyr package along with arrange and desc function to extract rows based on one column ordered in descending order.ExampleCreate the data frameLet’s create a data frame as shown below −x

Read More

How to create quantile regression plot with larger width of lines using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Nov-2021 328 Views

To create quantile regression plot with larger width of lines using ggplot2 in R, we can follow the below steps −First of all, create a data frame.Then, use stat_quantile function with size argument and geom_point function of ggplot2 package to create quantile regression plot.ExampleCreate the data frameLet’s create a data frame as shown below −x

Read More

How to remove a row from matrix in R by using its name?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Nov-2021 2K+ Views

To remove a row from matrix in R by using its name, we can follow the below steps −First of all, create a matrix.Then, add names to rows of the matrix.After that, subset the matrix by deselecting the desired row with negation and single square brackets for subsetting.ExampleCreate the matrixLet’s create a matrix as shown below −M

Read More

How to remove a column from matrix in R by using its name?

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

To remove a column from matrix in R by using its name, we can follow the below steps −First of all, create a matrixThen, add names to columns of the matrix.After that, subset the matrix by deselecting the desired column with negation and single square brackets for subsetting.ExampleCreate the matrixLet’s create a matrix as shown below −M

Read More

How to find the row total of columns having same name in data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Nov-2021 261 Views

To find the row total of columns having same name in data.table object in R, we can follow the below steps −First of all, create a data.table with some columns having same name.Then, use tapply along with colnames and sum function to find the row total of columns having same name.ExampleCreate the data.tableLet’s create a data.table as shown below −library(data.table) DT

Read More

How to extract the last n values of all elements of a list in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Nov-2021 2K+ Views

To extract the last n values of all elements of a list in R, we can follow the below steps −First of all, create a list.Then, use tail function with sapply function to extract the last n values of all elements in the list.Example 1Create the listLet’s create a list as shown below −List1

Read More
Showing 951–960 of 1,740 articles
« Prev 1 94 95 96 97 98 174 Next »
Advertisements