Server Side Programming Articles - Page 739 of 2650

How to find the percentage of zeros in each column of a data.table object in R?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:43:55

263 Views

To find the percentage of zeros in each column of a data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, use colSums function along with nrow function to find the percentage of zeros in each column.Example 1Create the data.table objectLet’s create a data.table object as shown below −library(data.table) y1

How to remove rows in R matrix that contains a specific number?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:40:54

597 Views

To remove rows in R matrix that contains a specific number, we can follow the below steps −First of all, create a matrix.Then, use single square subsetting with apply function to remove rows that contains a specific number.ExampleCreate the data frameLet’s create a data frame as shown below −M

How to convert values greater than a threshold into 1 in R data frame column?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:36:01

3K+ Views

To convert values greater than a threshold into 1 in R data frame column, we can follow the below steps −First of all, create a data frame.Then, use ifelse function to convert values greater than a threshold into 1.ExampleCreate the data frameLet’s create a data frame as shown below −x

How to subset R data frame rows if at least one or more values matches?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:34:14

421 Views

To subset R data frame rows if at least one or more values matches, we can follow the below steps −First of all, create a data frame.Then, use rowSums function along with sapply function and values for match to subset the data frame rows if at least one or more values matches.ExampleCreate the data frameLet’s create a data frame as shown below −x

How to repeat column values in R data frame by values in another column?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:31:31

3K+ Views

To repeat column values in R data frame by values in another column, we can follow the below steps −First of all, create a data frame.Then, use rep function along with cbind function to repeat column values in the matrix by values in another column.ExampleCreate the data frameLet’s create a data frame as shown below −x

How to standardize selected columns in R data frame?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:28:17

3K+ Views

To standardize selected columns in R data frame, we can follow the below steps −First of all, create a data frame.Then, use scale function with subsetting to standardize selected columns.ExampleCreate the data frameLet’s create a data frame as shown below −v1

How to convert a data frame into two column data frame with values and column name as variable in R?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:19:58

968 Views

To convert a data frame into two column data frame with values and column name as variable in R, we can follow the below steps −First of all, create a data frame.Then, use stack function to convert data frame.ExampleCreate the data frameLet’s create a data frame as shown below −x

How to extract number from string if string is in different format than normal in R data frame?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:17:14

125 Views

To extract number from string if string is in different format than normal in R data frame, we can follow the below steps −First of all, create a data frame.Then, use gsub function along with as.numeric function to extract the number.ExampleCreate the data frameLet’s create a data frame as shown below −x

How to extract number from string in R data frame?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:14:12

2K+ Views

To extract number from string in R data frame, we can follow the below steps −First of all, create a data frame.Then, use gsub function to extract number from string.ExampleCreate the data frameLet’s create a data frame as shown below −x

How to remove repeated numbers in sequence in R data frame column?

Nizamuddin Siddiqui
Updated on 11-Nov-2021 06:12:14

424 Views

To remove repeated numbers in sequence in R data frame column, we can follow the below steps −First of all, create a data frame.Then, use diff function and subsetting with single square brackets to remove repeated numbers in sequence.Example 1Create the data frameLet’s create a data frame as shown below −x

Advertisements