Nizamuddin Siddiqui has Published 2307 Articles

How to extract the split string elements in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Mar-2021 08:10:17

2K+ Views

To split string vector elements, we can use strsplit function. And if we want to extract the string elements after splitting then double and single square brackets will be used. The double square bracket will extract the string vector element and the single square will extract the element after splitting. ... Read More

How to display upper and lower quartiles through different line in a boxplot in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Mar-2021 07:52:21

122 Views

To display the upper and lower quartiles through different line in base R boxplot, we can use abline function but we need to find the quartiles inside abline using quantile for the respective quartiles. The lines created by using abline and quantiles and the boxplot function may not coincide because ... Read More

How to change the legend shape using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Feb-2021 12:17:30

1K+ Views

By default, the shape of legend is circular but we can change it by using the guides function of ggplot2 package. For example, if we have a data frame with two numerical columns say x and y, and one categorical column Group then the scatterplot between x and y for ... Read More

How to deal with error “undefined columns selected” while subsetting data in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Feb-2021 12:14:37

2K+ Views

When we do subsetting with the help of single square brackets we need to be careful about putting the commas at appropriate places. If we want to subset rows using the columns then comma needs to be placed before the condition. The “undefined columns selected” error occurs when we do ... Read More

How to collapse data frame rows in R by summing using dplyr?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Feb-2021 12:05:26

3K+ Views

To collapse data frame rows by summing using dplyr package, we can use summarise_all function of dplyr package. For example, if we have a data frame called df that has a categorical column say Group and one numerical column then collapsing of rows by summing can be done by using ... Read More

How to create a subset using character column with multiple matches in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Feb-2021 12:02:55

550 Views

Subsetting is one of the most important aspects of data analysis. One such situation could be subsetting the character column based on multiple values. For example, if a character column of an R data frame has 5 categories then we might want to extract only 2 or 3 or 4 ... Read More

How to find the frequency vector elements that exists in another vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Feb-2021 11:59:10

113 Views

If a vector value exists in another vector then we might want to find the frequency/count for such values in the other vector. For example, if we have two vectors say x and y, and some of the values in y exists in x as well. Therefore, we can find ... Read More

How to plot time series data with labels in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Feb-2021 11:54:39

435 Views

If we have time series data stored in a data frame then plotting the same as a time series cannot be done directly, also the labels for the series might not be possible directly. Therefore, we first need to convert the data frame to a time series object by using ... Read More

How to find the subtotal in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Feb-2021 11:50:16

516 Views

By subtotal we mean finding the sum of values based on grouping column. For example, if we have a data frame called df that contains three numerical columns as x, y, z and one categorical column say Group then the subtotal of x, y, z for each category in Group ... Read More

How to create a random vector of integers with increasing values only in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 11-Feb-2021 11:44:49

186 Views

To create a random vector of integers with increasing values, we can do random sampling with sample.int and for increasing values cummax function needs to be used. For example, to create a random vector of integers of size 5 up to values 5 starting from 1 can be done by ... Read More

Advertisements