Nizamuddin Siddiqui has Published 2307 Articles

How to create transparent bar plot using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:24:21

2K+ Views

To create transparent barplot using ggplot2, we can use alpha argument inside geom_bar function. For example, if we have a data frame called df that contains a categorical column say x and a numerical column say count then the bar plot with transparency can be created by using the command ... Read More

What is the difference between class and typeof function in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:24:02

4K+ Views

The class function in R helps us to understand the type of object, for example the output of class for a data frame is integer and the typeof of the same object is list because data frames are stored as list in the memory but they are represented as a ... Read More

How to recode factors in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:23:43

199 Views

Sometimes we have factor levels that can be combined or we want to group those levels in a single level. It is mostly done in situations where we have only one value for a particular factor level or there exists some theoretical concept that leads to combining the factor levels. ... Read More

How to find prime factors of a number in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:07:03

734 Views

A prime number is the number that is only divisible by itself and one. These prime numbers can also divide other numbers hence they become a factor of those numbers. For example, 5 is a prime number and it also divides 20. To find the prime factors of a number, ... Read More

How to delete a list element that only contains NA in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:03:31

329 Views

To delete a list element that only contains NA, we can use Filter function with Negate function. For example, if we have a list called LIST that contains one or more elements having all NA’s then we can delete those elements using the command −Filter(Negate(anyNA), LIST)Example1Consider the below list − Live ... Read More

How to find the object size in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:02:50

4K+ Views

To find the object size in R, we can use object.size function. For example, if we have a data frame called df then the size of df can be found by using the command object.size(df). Similarly, if we have a vector say x then it’s size can be found using ... Read More

How to detect multicollinearity in categorical variables using R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 13:02:06

1K+ Views

The multicollinearity is the term is related to numerical variables. It means that independent variables are linearly correlated to each other and they are numerical in nature. The categorical variables are either ordinal or nominal in nature hence we cannot say that they can be linearly correlated.ExampleConsider the below data ... Read More

How to find the column mean by excluding NA’s and if all values are NA then output NA in R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 12:59:35

748 Views

To find the column mean by excluding NA’s can be easily done by using na, rm but if we want to have NA if all the values are NA then it won’t be that straight forward. Therefore, in such situation, we can use ifelse function and return the output as ... Read More

How to find the sum of non-missing values in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 12:57:49

10K+ Views

To find the sum of non-missing values in an R data frame column, we can simply use sum function and set the na.rm to TRUE. For example, if we have a data frame called df that contains a column say x which has some missing values then the sum of ... Read More

How to subset a data.table object using a range of values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 12:54:18

2K+ Views

To subset a data.table object using a range of values, we can use single square brackets and choose the range using %between%. For example, if we have a data.table object DT that contains a column x and the values in x ranges from 1 to 10 then we can subset ... Read More

Advertisements