Nizamuddin Siddiqui has Published 2307 Articles

How to convert a vector into data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

7K+ 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

392 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

767 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

478 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 create boxplot in base R without axes labels?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 12:25:48

1K+ Views

The boxplot can be created by using boxplot function in base R but the Y−axis labels are generated based on the vector we pass through the function. If we want to remove the axis labels then axes = FALSE argument can be used. For example, if we have a vector ... Read More

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

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

10K+ 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 create boxplot for multiple categories with long names in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

165 Views

In base R, we use boxplot function to create the boxplots but if we have categorical vector and the corresponding numerical vector then the boxplot can be easily created. For this purpose, we should save those vectors in a data frame and use the $ operator and las = 2 ... Read More

How to generate a power sequence of two in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

5K+ 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

How to create a point chart with empty points using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

2K+ Views

The point chart can be created by using geom_point function and if we want to create a point chart for single vector then we should pass the vector in both the places inside aes function. Also, by default the points are complete black circles and if we want to change ... Read More

Advertisements