Nizamuddin Siddiqui has Published 2307 Articles

How to convert a numerical column into factor column in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Oct-2020 14:44:54

5K+ Views

Often, we find that the values that represent factor levels are recorded as numerical values, therefore, we need to convert those numerical values to factor. In this way, we can use the factor column properly in our analysis otherwise R program will treat the factors as numerical values and the ... Read More

How to use for loop to print all the elements of a list in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Oct-2020 14:41:45

2K+ Views

Applying for loop to a vector or a list is no different, we can simply use in the usual manner. For example, if we have a list called List and we want to print all the elements of the list then we can use the code for(i in List){print(i)}, here ... Read More

How to reduce the size of the area covered by legend in R for a plot created by using plot function?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Oct-2020 14:39:15

1K+ Views

By default, the area covered by legends for a plot created by using plot function is of full size that is 1 (the area size has a range of 0 to 1, where 1 refers to the full size and 0 refers to none). To reduce the size, we can ... Read More

How to find the statistical summary of an R data frame with all the descriptive statistics?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Oct-2020 14:36:44

320 Views

When we find statistical summary of an R data frame, we only get the minimum value, first quartile, median, mean, third quartile, and maximum value but in descriptive there are many other useful measures such as variance, standard deviation, skewness, kurtosis, etc. Therefore, we can use basicStats function of fBasics ... Read More

How to display R-squared value on scatterplot with regression model line in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Oct-2020 14:20:27

7K+ Views

The R-squared value is the coefficient of determination, it gives us the percentage or proportion of variation in dependent variable explained by the independent variable. To display this value on the scatterplot with regression model line without taking help from any package, we can use plot function with abline and ... Read More

How to find the absolute pairwise difference among values of a vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Oct-2020 14:15:54

346 Views

If a vector contains five values then there will be ten pairwise differences. For example, suppose we have five numbers starting from 1, then the pairwise combinations for these values will be (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), ... Read More

How to create a sequence of dates by using starting date in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Oct-2020 14:11:47

836 Views

The best way to create a sequence of anything is creating it with the help of seq function and this also applies to sequences of dates. But in case of dates, we need to read the dates in date format so that R can understand the input type and create ... Read More

How to create a contingency table with sum on the margins from an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Oct-2020 14:09:35

2K+ Views

The sum of rows and columns on the margins in a contingency table are always useful because they are used for different type of calculations such as odds ratio, probability etc. If an R data frame has factor columns then we can create a contingency table for that data frame ... Read More

How to concatenate vector with defined name to a list in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Oct-2020 16:54:09

84 Views

The concatenation of vector to a list simply means adding an external vector to the list we already have. For this purpose, we need to defined the vector with list function so that the R program understands that we are adding a list object to another list, otherwise the vector ... Read More

How to create a data frame with combinations of values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Oct-2020 16:36:25

459 Views

Suppose we have two values 0 and 1 then how many combinations of these values are possible, the answer is 8 and these combinations are (0, 0), (1, 0), (0, 1), (1, 1). In R, we can use expand.grid function to create these combinations but to save it in a ... Read More

Advertisements