Nizamuddin Siddiqui has Published 1958 Articles

How to calculate two period moving average for vector elements in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 12:59:59

239 Views

If we want to find the two−period moving average easily then it cannot be done in base R. We need to use rollmean function of zoo package that solves this problem in a single line of code. For example, if we have a vector x that contains hundred from starting ... Read More

How to italicize boxplot label in R using ggplot2?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 12:57:44

3K+ Views

Like every other tool for statistical analysis R does not display the labels of a boxplot in italics, thus if we want to do this, we need to do it manually. In ggplot2, we have a function scale_x_discrete that can be used to change the default font to italic using ... Read More

How to add named vectors of different sizes based on names in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 12:54:57

282 Views

If we have named vectors but the names come from same family then they cannot be added to each other direct to get the sum of values based on names. To do this, we need to use tapply function. For example, if we have three vectors defined as x, y, ... Read More

How to convert a vector into data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 12:47:17

9K+ Views

If we want to convert an object into a data frame then as.data.frame function can be used, we just need to read the object that we want to convert with as.data.frame. For example, if we have a vector x then it can be converted to data frame by using as.data.frame(x) ... Read More

How to create a regression model in R with interaction between all combinations of two variables?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 12:45:01

516 Views

The easiest way to create a regression model with interactions is inputting the variables with multiplication sign that is * but this will create many other combinations that are of higher order. If we want to create the interaction of two variables combinations then power operator can be used as ... Read More

What is the difference between ordered factors and unordered factors in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 12:38:37

1K+ Views

To understand the difference ordered factors and unordered factors, it is better to understand them by creating the factor vectors by using ordered argument with TRUE and FALSE options. For example, if we have a vector x then it can be ordered or unordered as factor(x, ordered=TRUE) and factor(x, ordered=FALSE).Example1 Live ... Read More

How to combine array of vectors in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 12:36:46

852 Views

To combine array of vectors we can use rbind function. For example, if we have multiple vectors say x, y, z of same size or different sizes but the total number of elements are even then we can use rbind(x, y, z) to combine those vectors. Check out the examples ... Read More

How to convert factor levels into character in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 12:28:19

5K+ Views

To convert factor levels into character then we can use as.character function by accessing the column of the data frame that contain factor values. For example, if we have a data frame df which contains a factor column named as Gender then this column can be converted into character column ... Read More

How to find p-value for correlation coefficient in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 12:22:12

12K+ Views

The t test is used to find the p−value for the correlation coefficient and on the basis of that we decide whether there exists a statistically significant relationship between two variables or not. In R, we can perform this test by using function cor.test. For example, if we have a ... Read More

How to generate a power sequence of two in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 12:15:49

6K+ Views

In R, for the calculation of power we can simply use power operator ^ and this will be also used in case of generating a power sequence. For example, if we want to generate a power sequence from 1 to 5 of 2 then we can use the code 2^(1:5) ... Read More

Advertisements