Found 26504 Articles for Server Side Programming

How to repeat a whole data.table object in R?

Nizamuddin Siddiqui
Updated on 08-Nov-2021 12:08:52

858 Views

To repeat a whole data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, use rep function to repeat the data.table object.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) x

How to find the number of columns where all row values are equal in data.table object in R?

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

393 Views

To find the number of columns where all row values are equal in data.table object in R, we can follow the below steps −First of all, create a data.table object.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 data.table objectLet’s create a data.table object as shown below −library(data.table) x

How to find the position of maximum of each numerical column if some columns are categorical in R data frame?

Nizamuddin Siddiqui
Updated on 08-Nov-2021 12:01:35

128 Views

To find the position of maximum of each numerical column if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to find the maximum of each numerical column if some columns are categorical.Example 1Create the data frameLet’s create a data frame as shown below −Level

How to find the cosine of each value in columns if some columns are categorical in R data frame?

Nizamuddin Siddiqui
Updated on 08-Nov-2021 11:55:33

359 Views

To find the cosine of each value in columns if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to find the cosine of each value in columns if some columns are categorical.ExampleCreate the data frameLet’s create a data frame as shown below −Level

How to create a binary random variable in R with given probability?

Nizamuddin Siddiqui
Updated on 08-Nov-2021 11:49:52

4K+ Views

To create a binary random variable in R with given probability, we can use the rbinom function with sample size argument n, success size argument size, and probability argument prob. To understand, how it can be done check out the below examples.Example 1Create the vector using rbinom function with n = 500, size = 1, and prob = 0.05 as shown below −x1

How to find the column median if some columns are categorical in R data frame?

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

217 Views

To find the column median if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to find the column median if some columns are categorical.Example 1Create the data frameLet’s create a data frame as shown below −Group

How to create a replacement column with multiple conditions and NA in R data frame?

Nizamuddin Siddiqui
Updated on 08-Nov-2021 11:42:27

519 Views

To create a replacement column with multiple conditions and NA in R data frame, we can follow the below steps −First of all, create a data frame.Then, use nested ifelse function to create a replacement column with multiple conditions.ExampleCreate the data frameLet’s create a data frame as shown below −x

How to find the column standard deviation if some columns are categorical in R data frame?

Nizamuddin Siddiqui
Updated on 08-Nov-2021 11:38:52

187 Views

To find the column standard deviation if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to find the column standard deviation if some columns are categorical.Example 1Create the data frameLet’s create a data frame as shown below −Group

How to remove dollar sign in R data frame?

Nizamuddin Siddiqui
Updated on 08-Nov-2021 11:33:25

1K+ Views

To remove dollar sign in R data frame, we can follow the below steps −First of all, create a data frame.Then, use gsub function along with lapply function to remove dollar sign.ExampleCreate the data frameLet’s create a data frame as shown below −Product

Convert a single column matrix into a diagonal matrix in R.

Nizamuddin Siddiqui
Updated on 08-Nov-2021 11:44:42

601 Views

A diagonal matrix is a type of square matrix that contains zero at non-diagonal elements starting from left-upper to right-bottom.To convert a single column matrix into a diagonal matrix in R, we can use diag function along with matrix function and use ncol argument where we can put the number of columns equal to the number of values in the single column matrix.Check out the Examples given below to understand how it can be done.Example 1Following snippet creates a sample matrix −M1

Advertisements