Found 26504 Articles for Server Side Programming

How to multiply row values in a data frame having multiple rows with single row data frame in R?

Nizamuddin Siddiqui
Updated on 12-Nov-2021 05:55:12

2K+ Views

To multiply row values in a data frame having multiple rows with single row data frame in R, we can follow the below steps −First of all, create a data frame with multiple rows and a data frame with single row.Then, use mapply function to multiply row values in the data frame having multiple rows with single row data frame.ExampleCreate the first data frameLet’s create a data frame as shown below −x

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

Nizamuddin Siddiqui
Updated on 12-Nov-2021 05:52:34

153 Views

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

How to find the percentage of zeros in each column of a data frame in R?

Nizamuddin Siddiqui
Updated on 12-Nov-2021 05:49:39

1K+ Views

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

How to multiply corresponding values from two data frames in R?

Nizamuddin Siddiqui
Updated on 12-Nov-2021 05:46:06

2K+ Views

To multiply corresponding values from two data frames in R, we can follow the below steps −First of all, create two data frames.Then, use mapply function to multiply corresponding values from those two data frames.ExampleCreate the first data frameLet’s create a data frame as shown below −df1

How to subset a matrix in R by ignoring a value in one of the columns?

Nizamuddin Siddiqui
Updated on 12-Nov-2021 05:43:23

264 Views

To subset a matrix in R by ignoring a value in one of the columns, we can follow the below steps −First of all, create a matrix.Then, use single square brackets to subset the matrix by ignoring a value in one of the columns.ExampleCreate the matrixLet’s create a matrix as shown below −M

How to create a column of first non-zero value in each row of an R data frame?

Nizamuddin Siddiqui
Updated on 12-Nov-2021 05:35:13

721 Views

To create a column of first non-zero value in each row of an R data frame, we can follow the below steps −First of all, create a data frame with some zero values.Then, use apply function and a custom function to find the first non-zero in each row of the data frame.ExampleCreate the data frameLet’s create a data frame as shown below −x

How to unsplit a split data.table object in R?

Nizamuddin Siddiqui
Updated on 12-Nov-2021 05:33:26

293 Views

To unsplit a split data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, use split function to split the data.table object.After that, use do.call function along with rbind function unsplit the data frame.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) Grp

How to standardize multiple columns not all in data.table object in R?

Nizamuddin Siddiqui
Updated on 12-Nov-2021 05:27:52

288 Views

To standardize multiple columns not all in data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, subset the columns with single square brackets and use lapply, list and scale function to standardize those columns.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) x

How to create a matrix with equal rows in R?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 08:26:43

762 Views

If we have a single row for a matrix then creation of a matrix with equal rows can be easily done with the help of rep function and if we do not have the row then we would need to pass the row value inside rep function.Check out the below examples to understand how to create a matrix with equal rows if one row is known.Example 1Consider the below vector −Row_1

How to impute missing values by random value for a single column in R?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 08:19:48

755 Views

To impute missing values by random value for a single column in R, we can use impute function from Hmisc package.For example, if we have a data frame called that contains a column say C which has some missing values then we can use the below given command to fill those missing values randomly −df$C

Advertisements