Nizamuddin Siddiqui has Published 2307 Articles

How to find the fractional power of a negative number in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 07:35:04

228 Views

To find the fractional power of a negative number, we can find the power separately for the numerator and denominator where denominator will have the numerator 1. For example, if we have a vector called x that contains a single value -10 then the fractional power 15/7 of x can ... Read More

How to find the sum of every n values if missing values exists in the R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 07:32:42

565 Views

To find the sum of every n values in R data frame columns if there exist missing values, we can use rowsum function along with rep function that will repeat the sum for rows and na.rm=TRUE to exclude the rows with missing values. For example, if we have a data ... Read More

How to check if an R matrix column contains only duplicate values?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 07:25:41

135 Views

To check if an R matrix column contains only duplicate values, we can use dim function for the dimension of the column after accessing the matrix column with table function. For example, if we have a matrix called M having five columns then we can check whether first column contains ... Read More

How to find the number of levels in R for a factor column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 07:21:09

684 Views

To find the number of levels in R for a factor column, we can use length function along with unique function. For example, if we have a data frame called df that contains a factor column X then we can find the number of levels in the factor column using ... Read More

How to replace space between two words with underscore in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 07:17:38

2K+ Views

To replace space between two words with underscore in an R data frame column, we can use gsub function. For example, if we have a data frame called df that contains character column x having two words having a single space between them then we can replace that space using ... Read More

How to find the standard deviation for rows in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 07:11:49

722 Views

To find the standard deviation for rows in an R data frame, we can use mutate function of dplyr package and rowSds function of matrixStats package. For example, if we have a data frame called df that contains two columns x and y then we can find the standard deviation ... Read More

How to find the correlation between corresponding columns of two matrices in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 07:05:10

661 Views

To find the correlation between corresponding columns of two matrices, we can use mapply function but we will have to read the matrices using as.data.frame function. For example, if we have two matrices called M_1 and M_2 and each of these matrices contains 5 columns then the correlation between corresponding ... Read More

How to delete matrix rows if a particular column value satisfies some condition in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 06:58:30

704 Views

To delete matrix rows if a particular column satisfies some condition, we can use subsetting with single square brackets and take the subset of the matrix based on the condition. For example, if we have a matrix M and want to delete rows if column first of M do not ... Read More

How to filter rows by excluding a particular value in columns of the R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 06:49:48

3K+ Views

To filter rows by excluding a particular value in columns of the data frame, we can use filter_all function of dplyr package along with all_vars argument that will select all the rows except the one that includes the passed value with negation. For example, if we have a data frame ... Read More

How to set the range for boxplot in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Mar-2021 06:46:24

2K+ Views

By default, R considers the vector or the data frame column values. But if we want to set the range for boxplot in base R, we can use ylim argument within the boxplot function. For example, if we have a vector called x that contains values starting from 21 to ... Read More

Advertisements