Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 97 of 196

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 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 can use the following code −seq(from=as.POSIXct("2020-10-10 14:00"), to=as.POSIXct("2020-10-10 16:00"), by="min")Exampleseq(from=as.POSIXct("2020-01-01 00:01"), to=as.POSIXct("2020-01-01 01:00"), by="min")Output[1] "2020-01-01 00:01:00 IST" "2020-01-01 00:02:00 IST" [3] "2020-01-01 00:03:00 IST" "2020-01-01 00:04:00 IST" [5] "2020-01-01 00:05:00 IST" "2020-01-01 00:06:00 IST" [7] "2020-01-01 00:07:00 IST" "2020-01-01 00:08:00 IST" [9] "2020-01-01 00:09:00 IST" "2020-01-01 00:10:00 IST" [11] "2020-01-01 ...

Read More

How to find the difference between regression line and the points in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 327 Views

The difference between regression line and the points on the scatterplot are actually the residuals, thus we need to calculate the residual from the model object. This can be simply done by using residuals function. For example, if we create a linear model defined as Model between x and y then the residuals will be found as residuals(Model).Consider the below data frame −Exampleset.seed(999) x1

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 685 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 find the cumulative sum for all factor levels together, we must find the cumulative sums for each level. This can be easily done by using ave function.ExampleConsider the below data frame −set.seed(15) x1

Read More

How to create histogram with relative frequency in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ 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 we want to create a histogram with relative frequencies then it can be done as PlotRelativeFrequency(hist(x)).ExampleConsider the below vector −x

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ 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 contain many values after decimal point and we can limit those values to 4 or use any other limit using round function.Examplex1

Read More

How to generate a normal random vector using the mean of a vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

To create a normal random vector, we can use rnorm function with mean and standard deviation as well as without passing these arguments. If we have a different vector derived from another distribution or simply represent some numbers then we can use the mean of that vector in the rnorm function for mean argument.Exampleset.seed(101) x1

Read More

How to join points in a point chart with lines using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 655 Views

Usually, a point chart is created to assess the relationship or movement of two variables together but sometimes these points are scattered in a way that makes confusion. Hence, data analyst or researcher try to visualize this type of graph by joining the points with lines. In ggplot2, this joining can be done by using geom_line() function.Consider the below data frame −Exampleset.seed(111) x

Read More

How to find the index of the last occurrence of repeated values in a vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 609 Views

Indexing helps us to understand the location of the value in the vector. If we have a vector that contains repeated values then we might want to figure out the last occurrence of the repeated value. For example, if we have a vector x that contains 1, 1, 2, 1, 2 then the last occurrence of repeated values will be 4 and 5 because the last 1 is at 4th position and 2 is at the 5th position. We can find this by using tapply function in R.Examplex1

Read More

How to take a subset of a matrix in R with finite values only if the matrix contains NA and Inf values?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 455 Views

If we have a matrix that contains NA or Inf values and we want to take the subset of that matrix with finite values then only the rows that do not contain NA or Inf values will be the output. We can do this in R by using rowSums and is.finite function with negation operator !.Exampleset.seed(999) M1

Read More

How to find the maximum of factor levels in numerical column and return the output including other columns in the R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 799 Views

When we have factor column that helps to differentiate between numerical column then we might want to find the maximum value for each of the factor levels. This will help us to compare the factor levels in terms of their maximum and if we want to do this by getting all the columns in the data frame then aggregate function needs to be used with merge function.Consider the below data frame −Exampleset.seed(78) Group

Read More
Showing 961–970 of 1,958 articles
« Prev 1 95 96 97 98 99 196 Next »
Advertisements