## How to find the number of zeros in each column of a matrix in R?

Updated on 15-Nov-2021 06:28:02
To find the number of zeros in each column of a matrix in R, we can follow the below steps −First of all, create a matrix.Then, use colSums function to find the number of zeros in each column.Example 1Create the matrixLet’s create a matrix as shown below −M1

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

Updated on 15-Nov-2021 06:22:07
To find the number 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 to find the number of zeros in each column.Example 1Create the data.table objectLet’s create a data.table as shown below −library(data.table) x1

## How to separate two values in single column in data.table object in R?

Updated on 15-Nov-2021 06:18:16
To separate two values in single column in data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, use separate function from tidyr package to separate the values in single column.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) DT

## How to convert first letter into capital in single column data.table object in R using a function?

Updated on 15-Nov-2021 06:15:09
To convert first letter into capital in single column data.table object in R, we can follow the below steps −First of all, create a data.table object with string column.Then, use capitalize function from R.utils package to convert first letter into capital in single columnExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) Students

## How to convert first letter into capital in data.table object column in R?

Updated on 15-Nov-2021 06:12:11
To convert first letter into capital in data.table object column in R, we can follow the below steps −First of all, create a data.table object with string column.Then, use sub function to convert first letter into capital in string column.ExampleCreate the data.table objectLet’s create a data.table as shown below −library(data.table) Countries

## How to remove a particular value from a vector in R?

Updated on 12-Nov-2021 08:37:14
To remove a particular value from a vector, we can use negation of value.For example, if we have a vector called V that contains repetitive values starting from 1 to 10 and if we want to remove all 10s from V then we can use the command given below −V

## How to find rows in an R data frame that do not have missing values?

Updated on 12-Nov-2021 08:27:59
Dealing with missing values is one of the most critical task in data analysis. If we have a large amount of data then it is better to remove the rows that contains missing values. For the removal of such rows we can use complete.cases function.For example, if we have a data frame called df that contains some missing values then we can remove the rows with missing values using the below given command −df[complete.cases(df),]Example 1Following snippet creates a sample data frame −x1

## How to highlight a value with underline in base R plot?

Updated on 12-Nov-2021 08:24:01
To highlight a value with underline in base R plot, we can use underline function within text function. The text function will be used to define the value that we need to underline in the plot and underline function will only underline that part.Check out the below given example to understand how it works.ExampleTo highlight a value with underline in base R plot, use the code given below −plot(1:5)OutputIf you execute the above given code, it generates the following output −To highlight a value with underline in base R plot, add the following code to the above code −plot(1:5) text(4, ... Read More

## How to find the last non-missing value in each column of a data.table object?

Updated on 12-Nov-2021 08:22:30
To find the last non-missing value in each column of a data.table object, we can use lapply function along with tail function for NA values.For example, if we have a data.table object called DT then we can find the last non-missing value in each column of DT by using the below given command −DT[,lapply(.SD,function(x) tail(x[!is.na(x)],1))]Example 1Following snippet creates a data.table object −library(data.table) x1

## Find the combination of columns for correlation coefficient greater than a certain value in R

Updated on 12-Nov-2021 08:13:33
To find the combination of columns for correlation coefficient greater than a certain value, we would first need to create the correlation matrix and then melt the correlation with the help if melt function of reshape2 package. After that subset of the output will be taken based on the value of the correlation coefficient.Check out the below examples to understand how it works.Example 1Following snippet creates a sample data frame −x1