Articles on Trending Technologies

Technical articles with clear explanations and examples

Count rows/columns with sum equals to diagonal sum in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 269 Views

We are given a matrix which is a 2-D array having rows and columns and the task is to calculate the count of sum of all the rows and columns such that it is equal to the sum of either principal or secondary matrix.Input −int arr[row][col] = {    { 4, 1, 7 },    { 10, 3, 5 },    { 2, 2, 11} }Output − Count of rows/columns with sum equals to diagonal sum are &mins; 2Explanation −sum of principal diagonal is: 4 + 3 + 11 = 18 and sum of secondary diagonal is: 7 + 3 ...

Read More

Count number of occurrences (or frequency) in a sorted array in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 2K+ Views

We are given a sorted array of integer type elements and the number let’s say, num and the task is to calculate the count of the number of times the given element num is appearing in an array.Input − int arr[] = {1, 1, 1, 2, 3, 4}, num = 1Output − Count of number of occurrences (or frequency) in a sorted array are − 3Input − int arr[] = {2, 3, 4, 5, 5, 6, -7}, num = 5Output − Count of number of occurrences (or frequency) in a sorted array are − 2Input − int arr[] = {-1, ...

Read More

How to create a line chart using ggplot2 with a vertical line in R?

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

In general, the line chart is drawn to view the trend of something and we might also have some threshold point for that trend, for example, if blood pressure is plotted then we might want to show 60 mm Hg as well because this is the lowest acceptable value for blood pressure recommended by doctors. Therefore, it can be plotted as a vertical line if we want to plot blood pressures of a person. Similarly, there can be many situations where we can use a vertical line to visualize the threshold value. This can be achieved in ggplot2 with the ...

Read More

Count number of sub-sequences with GCD 1 in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 462 Views

We are given an array of integer elements and the task is to find the sub-sequences from the given array which are having GCD as 1. GCD is the greatest common divisor of two or more integers that divides the given numbers entirely and greatest amongst all.Input − int arr[] = {3, 4, 8, 16}Output − Count of number of sub-sequences with GCD 1 are − 7Explanation −The sub-sequences that can be formed from the given array with GCD as 1 are (3, 4), (3, 8), (3, 16), (4, 3), (8, 3), (16, 3), (3, 4, 8)Input − int arr[] ...

Read More

How to check if two data frames same or not in R?

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

Two data frames can be same if the column names, row names and all the values in the data frame are exactly same. We might to check this for data frames that we expect to be same, for example, if we have two data sets each one of have same number of rows, same number of columns, same data type for each of the columns, and the data view shows that values are same then it is worth checking whether the complete data sets are same or not. To do this checking in R, we can use identical function.Examplesdf1

Read More

How to initialize a data frame with variable names in R?

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

There are many ways to initialize a data frame in R but initializing with matrix is the best among them because creating the data frame with matrix help us to avoid entering the wrong number of columns and the wrong number of rows. After initializing the matrix, we can simply use as.data.frame to convert the matrix into a data frame and that’s it.Examplesdf1

Read More

How to increase the width of the lines in the boxplot created by using ggplot2 in R?

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

When we create a boxplot using ggplot2, the default width of the lines in the boxplot is very thin and we might want to increase that width to make the visibility of the edges of the boxplot clearer. This will help viewers to understand the edges of the boxplot in just a single shot. We can do this by using lwd argument of geom_boxplot function of ggplto2 package.ExampleConsider the below data frame −> ID Count df head(df, 20)Output ID Count 1 S1 20 2 S2 14 3 S3 17 4 S4 30 5 S1 17 6 S2 23 7 S3 36 ...

Read More

How to deal with missing values to calculate correlation matrix in R?

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

Often the data frames and matrices in R, we get have missing values and if we want to find the correlation matrix for those data frames and matrices, we stuck. It happens with almost everyone in Data Analysis but we can solve that problem by using na.omit while using the cor function to calculate the correlation matrix. Check out the examples below for that.ExampleConsider the below data frame −> x1 x2 x3 x4 df head(df, 20)Output x1     x2    x3    x4 1 2 2.6347839 4 2.577690 2 3 0.3082031 1 6.250998 3 1 0.3082031 3 7.786711 4 1 ...

Read More

How to create cumulative sum chart with count on Y-axis in R using ggplot2?

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

Cumulative sums are often used to display the running totals of values and these sums also help us to identify the overall total. In this way, we can analyze the variation in the running totals over time. To create the cumulative sum chart with count on Y-axis we can use stat_bin function of ggplot2 package.ExampleConsider the below data frame −> x df head(df, 20)Output      x 1 1.755900133 2 1.185746239 3 0.821489888 4 1.358420721 5 2.719636441 6 2.885153151 7 1.131452570 8 0.302981998 9 0.433865254 10 2.373338327 11 0.428436149 12 1.835789725 13 2.600838211 14 2.108302471 15 1.164818373 16 1.547473189 17 ...

Read More

How to add a new column in an R data frame with count based on factor column?

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

While doing the data analysis, often we have to deal with factor data and we might want to find the frequency or count of a level of factor and the other variable combination. This helps us to make comparison within and between factor levels. Therefore, we can add a new column as count to find the required frequency and it can be done by using group_by and mutate function of dplyr package.ExampleConsider the below data frame −> Group Rating df head(df, 20)Output   Group Rating 1    A    1 2    B    6 3    C    2 4 ...

Read More
Showing 26601–26610 of 61,297 articles
Advertisements