Server Side Programming Articles

Page 1254 of 2109

How to write a long line for the X-label of a scatterplot in R using ggplot2?

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

When we create a plot in R, the variable names are automatically plotted as axes labels but sometimes we want to give a brief detail of the X-label or a Y-label. If that brief is not small so that the expression function can contain the length of the label then it becomes difficult but it can be done with the help of atop inside expression.ExampleConsider the below data frame −set.seed(123) x

Read More

Sum of upper triangle and lower triangle in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 1K+ Views

In this problem, we are given a matrix. Our task is to create a program to print the sum of upper triangle and lower triangle.Lower triangleM00                     0             0       …        0 M10                     M11               0       …        0 M20                     M21               M22      …     ...

Read More

Sum of XOR of all pairs in an array in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 2K+ Views

In this problem, we are given an array arr[] of n integers. Our task is to create a program to find the sum of XOR of all pairs in an array.Let’s take an example to understand the problem, Input: arr[] = {5, 1, 4} Output: 10 Explanation: the sum of all pairs: 5 ^ 1 = 4 1 ^ 4 = 5 5 ^ 4 = 1 sum = 4 + 5 + 1 = 10One simple approach to solve this problem is to run nested loops and find all pairs of numbers. Find XOR of each pair and add ...

Read More

How to remove NULL values from a list in R?

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

The value NULL is used to represent an object especially a list of length zero. If a list contains NULL then we might want to replace it with another value or remove it from the list if we do not have any replacement for it. To remove the NULL value from a list, we can use the negation of sapply with is.NULL.Examplesx

Read More

How to find the maximum using aggregate and get the output with all the columns in R?

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

When we use aggregate function to find maximum or any other value, the output of the aggregation does not provide all the columns that corresponds to the maximum value. Therefore, we need to merge the data frame obtained by using aggregate with the original data frame. In this way, we will get only those rows that are common between the new data frame and the original one.ExampleConsider the below data frame −set.seed(99) x1

Read More

Find triplet such that number of nodes connecting these triplets is maximum in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 159 Views

In this tutorial, we will be discussing a program to find triplet such that number of nodes connecting these triplets is maximum.For this we will be provided with a tree with N nodes. Our task is to find a triplet of nodes such that the nodes covered in the path joining them in maximum.Example#include #define ll long long int #define MAX 100005 using namespace std; vector nearNode[MAX]; bool isTraversed[MAX]; //storing the required nodes int maxi = -1, N; int parent[MAX]; bool vis[MAX]; int startnode, endnode, midNode; //implementing DFS to search nodes void performDFS(int u, int count) {    isTraversed[u] ...

Read More

How to convert two columns of an R data frame to a named vector?

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

If two columns are of a form such that one column contains the name of the vector values and another column having the values of a vector then we might want to convert them into a vector. To do this, we can simply read the vectors with their data type and structure them with structure function.Example 1x1

Read More

Querying the number of distinct colors in a subtree of a colored tree using BIT in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 256 Views

In this tutorial, we will be discussing a program to find querying the number of distinct colors in a subtree of a colored tree using BIT.For this we will be provided with rooted tree where each node has a color denoted by given array. Our task is to find all the distinct coloured nodes below the given node in the tree.Example#include #define MAXIMUM_COLOUR 1000005 #define MAXIMUM_NUMBER 100005 using namespace std; vector tree[MAXIMUM_NUMBER]; vector table[MAXIMUM_COLOUR]; int isTraversing[MAXIMUM_COLOUR]; int bit[MAXIMUM_NUMBER], getVisTime[MAXIMUM_NUMBER], getEndTime[MAXIMUM_NUMBER]; int getFlatTree[2 * MAXIMUM_NUMBER]; bool vis[MAXIMUM_NUMBER]; int tim = 0; vector< pair< pair, int> > queries; //storing results of each ...

Read More

How to extract the p-value and F-statistic from aov output in R?

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

The analysis of variance technique helps us to identify whether there exists a significant mean difference in more than two variables or not. To detect this difference, we either use F-statistic value or p-value. If the F-statistic value is greater than the critical value of F or if p-value is less than the level of significance then we say that at least one of the means is significantly different from the rest. To extract the p-value and F-statistic value, we can make use of summary function of the ANOVA model.Exampleset.seed(123) Group

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 367 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
Showing 12531–12540 of 21,090 articles
Advertisements