Nizamuddin Siddiqui has Published 2307 Articles

How to check if a string contains only one type of character in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 13:13:27

341 Views

If a string contains more than one character then all of them could be same or different. If we want to check if a string contains only one type of character, then stri_count_fixed function of stringi package will be used with nchar function.Check out the below given examples to understand ... Read More

How to split a vector into smaller vectors of consecutive values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 13:09:00

626 Views

To split a vector into smaller vectors of consecutive values, we can use split function with cumsum function.For example, if we have a vector called X that contains some consecutive values then we split X into smaller vectors of consecutive values by using the command given below −split(x, cumsum(c(1, diff(x)!=1)))Example ... Read More

How to find the mean based on single group value in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 13:07:53

711 Views

To find the mean based on single group value in an R data frame, we can use mean function with subsetting through single square brackets.For example, if we have a data frame called df that contains a categorical column say C having three groups Low, Medium, High and a numerical ... Read More

How to fill a data.table row with missing values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 13:01:30

399 Views

Instead of filling missing values, we sometimes need to replace the data with missing values. This might be required in situations when missing values are coded with a number or the actual values are not useful or sensible for the data study. Also, we might want to replace the values ... Read More

How to create a wide vertical line using ggplot2 with different color in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 12:56:18

3K+ Views

To create a vertical line using ggplot2, we can use geom_vline function of ggplot2 package and if we want to have a wide vertical line with different color then lwd and colour argument will be used. The lwd argument will increase the width of the line and obviously colour argument ... Read More

How to create a dotted vertical line using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 12:54:26

7K+ Views

To create a vertical line using ggplot2, we can use geom_vline function of ggplot2 package and if we want to have a dotted vertical line then linetype will be set to 3 inside the same function. To draw the line, we will have to provide xintercept because the line will ... Read More

How to subset matrix row values based on different columns?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 08:27:30

72 Views

Suppose we have a matrix called M that contains three columns and we want to subset row values of M but from different columns that means the subset will not have values only from a single column.Hence, before creating the subset we first need to find the column numbers that ... Read More

How to find the row products for each row in an R matrix?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 08:16:49

109 Views

To find the row products for each row in an R matrix, we can use rowProds function of matrixStats package.For Example, if we have a matrix called MATRIX then we can find the row products for each row in MATRIX by using the command given below −rowProds(MATRIX)Example 1Following snippet creates ... Read More

How to create pie chart in base R with labels?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 08:07:16

134 Views

A pie chart is a circular representation of data which is created for either nominal data or ordinal data. The slices in the pie chart depends on the magnitude of the data values. If we want to create a pie chart in base R with then pie function can be ... Read More

Convert a numeric column to binary factor based on a condition in R data frame

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 10-Nov-2021 08:00:27

3K+ Views

To convert a numeric column to binary factor based on a condition in R data frame, we can use factor function along with ifelse function.For Example, if we have a data frame called df that contains a numerical column say Num and we want to convert it to a binary ... Read More

Advertisements