Nizamuddin Siddiqui has Published 2307 Articles

How to convert row index number or row index name of an R data frame to a vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 13:05:34

359 Views

We might want to extract row index irrespective of its type (whether numeric or string) to do some calculations if it is incorrectly set as a row index. It happens during the data collection process or incorrect processing of data. Also, since row indexes are helpful to access row we ... Read More

How to create a scatterplot in R using ggplot2 with transparency of points?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 13:00:03

218 Views

A scatterplot is used to observe the relationship between two continuous variables. If the sample size is large then the points on the plot lie on each other and does not look appealing. Also, the interpretation of such type of scatterplots is not an easy task, therefore, we can increase ... Read More

How to find the mean of each variable using dplyr by factor variable with ignoring the NA values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:56:27

235 Views

If there are NA’s in our data set for multiple values of numerical variables with the grouping variable then using na.rm = FALSE needs to be performed multiple times to find the mean or any other statistic for each of the variables with the mean function. But we can do ... Read More

How to join two data frames with the same row order using dplyr in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:50:47

132 Views

When we have one common column in two data frames then joining of those data frames might be used to create a bigger data frame. This will help us to analyze a combined data set with many characteristics. We can do this by using inner_join function of dplyr package.ExampleConsider the ... Read More

How to convert multiple numerical variables to factor variable in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:45:17

1K+ Views

Sometimes the data type for a variable is not correct and it is very common that a factor variable is read as a numeric variable, especially in cases where factor levels are represented by numbers. If we do not change the data type of a factor variable then the result ... Read More

How to create an empty matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:39:17

4K+ Views

An empty matrix can be created in the same way as we create a regular matrix in R but we will not provide any value inside the matrix function. The number of rows and columns can be different and we don’t need to use byrow or bycol argument while creating ... Read More

How to plot means inside boxplot using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:30:27

388 Views

When we create a boxplot, it shows the minimum value, maximum value, first quartile, median, and the third quartile but we might want to plot means as well so that the comparison between factor levels can be made on the basis of means also. To create this type of plot, ... Read More

How to create a scatterplot in R with legend position inside the plot area using ggplot2?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:27:10

228 Views

Legends help us to differentiate the values of the response variable while creating the scatterplot. In this way, we can understand how one level of a factor variable affects the response variable. The legend is preferred to be positioned at left bottom, top right, top left, and bottom right. We ... Read More

How to create a subset for a factor level in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:24:52

4K+ Views

In data analysis, we often deal with factor variables and these factor variables have different levels. Sometimes, we want to create subset of the data frame in R for specific factor levels to analyze the data only for that particular level of the factor variable. This can be simply done ... Read More

How to convert a vector into matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 12-Aug-2020 12:20:02

10K+ Views

To convert a vector into matrix, just need to use matrix function. We can also define the number of rows and columns, if required but if the number of values in the vector are not a multiple of the number of rows or columns then R will throw an error ... Read More

Advertisements