Nizamuddin Siddiqui has Published 2307 Articles

How to generate random samples rounded to 4 decimal places in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 09:49:47

802 Views

Random samples can be generated in many ways such as using discrete and continuous distributions, using integer vectors, using numerical vectors, using character vectors and/or factor vectors, also with columns of a data set. If we have the sample that is continuous in nature then the values are likely to ... Read More

How to extract string before slash from a vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 09:48:06

2K+ Views

If a vector contains string values and they are separated with a special character (This special character can be anything, also it is not necessarily to be a special character) and we want to extract only the values that exists before that special then we can use gsub function. For ... Read More

How to create histogram with relative frequency in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 09:46:49

1K+ Views

The relative frequency histogram can be created for the column of an R data frame or a vector that contains discrete data. For this purpose, we can use PlotRelativeFrequency function of HistogramTools package along with hist function to generate histogram. For example, if we have a vector x for which ... Read More

How to find the cumulative sum for factor levels in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 09:42:55

430 Views

Cumulative sums are mostly used in descriptive analysis of data but sometimes we might want to calculate them in understanding the time series analysis for moving sums but it is very rare. If we have a factor column in an R data frame then it would not make sense to ... Read More

How to create a sequence of time in minutes with date in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 09:38:27

1K+ Views

To create a sequence of time in minutes with date we can use seq function and define the date and time with as.POSIXct. For example, if we want to generate a sequence of time between 2 pm on tenth October 2020 to 4 pm on the same date then we ... Read More

How to omit missing values and move the values to places to complete the data frame structure in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 09:36:55

73 Views

When we have alternative missing values in two columns that makes the data frame look filled with values at alternate places in columns as well. In this case, we might want to remove those missing values so that the data frame becomes complete without any missing value. For this purpose ... Read More

How to create regression model line in a scatterplot created by using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 09:33:46

245 Views

To add a regression model line in a scatterplot created by using ggplot2, we need to use geom_smooth function to define the line for linear model. For example, if we have a data frame df that contains independent variable x and the dependent variable y then the regression line can ... Read More

How to create a plot with cross sign in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 09:31:03

260 Views

In base R, the plot with different shape of points can be created by using pch argument inside the plot function but if we want to use any sign that is not designed for pch argument by default then we should pass that particular sign. For example, if we want ... Read More

How to find the size of the plotting window in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 09:29:08

2K+ Views

The plotting window size can be found by using dev.size function and we can pass in for inches and cm for centimeters. For example, if we create a plot then we can use dev.size("in") to find the plot size in inches and dev.size("cm") to find the size in centimeters.ExampleConsider the ... Read More

How to convert columns of an R data frame into rows?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 09:26:48

20K+ Views

If the row values are incorrectly recorded into columns then we might want to convert the columns into rows. Thus, to convert columns of an R data frame into rows we can use transpose function t. For example, if we have a data frame df with five columns and five ... Read More

Advertisements