Nizamuddin Siddiqui has Published 2307 Articles

How to remove rows that contains all zeros in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 11:23:54

8K+ Views

Often, we get missing data and sometimes missing data is filled with zeros if zero is not the actual range for a variable. In this type of situations, we can remove the rows where all the values are zero. For this purpose, we can use rowSums function and if the ... Read More

How to generate the permutation of x values in y positions with fixed row sums in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 11:22:27

84 Views

To generate a permutation of x values in y positions, we can use expand.grid function. For example, if we want to generate three columns for the range of values 0 to 5 then it can be done in R by using the below command − Live Demox

How to calculate mahalanobis distance in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 11:18:08

579 Views

The Mahalanobis distance is the relative distance between two cases and the centroid, where centroid can be thought of as an overall mean for multivariate data. We can say that the centroid is the multivariate equivalent of mean. If the mahalanobis distance is zero that means both the cases are ... Read More

How to find the frequency of a particular string in a column based on another column in an R data frame using dplyr package?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 11:16:40

411 Views

When we have two or more categorical columns in an R data frame with strings as level of the categories or numbers as strings/integers then we can find the frequency of one based on another. This will help us to identify the cross-column frequencies and we can understand the distribution ... Read More

How to create geometric progression series in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 11:15:18

2K+ Views

A geometric progression series is a sequence of numbers in which all the numbers after the first can be found by multiplying the previous one by a fixed number. To generate a geometric progression series in R, we can use seq function. For example, to generate a geometric progression series ... Read More

How to create a sample from an R data frame if weights are assigned to the row values?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 11:14:33

871 Views

To create a random sample in R, we can use sample function but if the weight of the values is provided then we need to assign the probability of the values based on the weights. For example, if we have a data frame df that contains a column X with ... Read More

How to convert a data frame column to date that contains integer values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 11:13:01

788 Views

If we have an integer column that actually contains date values, for example having 29th September 2020 as 20200929 then we can convert it to date by using transform function by reading the dates with as.Date function but as.character will also be needed so that as.Date function can read the ... Read More

How to create scatterplot for factor levels in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 11:05:22

449 Views

To create a scatterplot for factor levels, we can use facet_grid function of ggplot2 package. For example, suppose we have a factor column in a data frame df defined as F and numerical columns defined as x and y then the scatterplot for the factor levels can be created as ... Read More

How to change the font size of legend in base R plot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 11:03:26

2K+ Views

In base R, we can use legend function to add a legend to the plot. For example, if we want to create a histogram with legend on top-right position then we can use legend("topright", legend="Normal Distribution") and if we want to change the font size then we need to as ... Read More

How to find the union of two vectors in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 08:04:12

2K+ Views

The union of vectors return all the unique values in both the vectors. For example, if we have a vector x that contains 1, 2, 3, 4, 2, 3, 4, 1, 1, 4 and another vector that contains 2, 1, 2, 4, 5, 7, 5, 1, 2, 3, 7, 6, ... Read More

Advertisements