Server Side Programming Articles

Page 1222 of 2109

How to find the absolute distance between columns of an R data frame?

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

The absolute distance can be found by calculating the difference between column values. And if we want the distance to be absolute then we would be need to use abs function. For example, suppose we have a data frame df that contain columns x and y then the absolute distance can be found by using df$Absolute_Distance set.seed(274) > x1 y1 df1 df1Output  x1 y1 1 6 11 2 1 4 3 4 2 4 7 12 5 4 5 6 6 10 7 6 14 8 6 8 9 2 11 10 3 8 11 3 8 12 2 6 ...

Read More

Number of Connected Components in an Undirected Graph in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have n nodes and they are labeled from 0 to n - 1 and a list of undirected edges, are also given, we have to define one function to find the number of connected components in an undirected graph.So, if the input is like n = 5 and edges = [[0, 1], [1, 2], [3, 4]], then the output will be 2To solve this, we will follow these steps −Define a function dfs(), this will take node, graph, an array called visited, if visited[node] is false, then −visited[node] := truefor initialize i := 0, when i < size ...

Read More

How to find the minimum and maximum of columns values in an R data frame?

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

The range function in R provides the minimum and maximum values instead of the difference between the two. Hence, we can find the minimum and maximum by using range function but for a data frame we cannot use it directly. Check out the below examples to understand how it works.Example1> set.seed(974) > x1 x2 x3 df1 df1Output x1 x2 x3 1 0 6 10 2 0 7 10 3 3 3 11 4 2 7 9 5 3 2 5 6 3 4 7 7 2 7 7 8 2 8 5 9 0 4 9 10 2 2 11 ...

Read More

Largest BST Subtree in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 218 Views

Suppose we have a binary tree; we have to find the largest subtree of it where largest means subtree with largest number of nodes in it.So, if the input is like, then the output will be 3, as the Largest BST Subtree, in this case, is the highlighted one.To solve this, we will follow these steps −Define one structure called data, there will be four values, size, maxVal, minVal, and ok, the ok can hold only true/false valuessolve(TreeNode * node)if node is null, then &miuns;return Data by initializing (0, infinity, -infinity, true)left := solve(left of node)left := solve(right of node)Define ...

Read More

Android Unlock Patterns in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have an Android 3x3 key lock screen and two integers m and n, the values of m and n are in range 1 ≤ m ≤ n ≤ 9, We have to count the total number of unlock patterns of the Android lock screen, which consist of minimum of m keys and maximum n keys.The rule is like, each pattern must connect at least m keys and at most n keys. All the keys must be unique. If there is a line connecting two consecutive keys in the pattern passes through any other keys, the other keys must ...

Read More

How to create a covariance matrix in R?

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

To create a covariance matrix, we first need to find the correlation matrix and a vector of standard deviations is also required. The correlation matrix can be found by using cor function with matrix object. For example, if we have matrix M then the correlation matrix can be found as cor(M). Now we can use this matrix to find the covariance matrix but we should make sure that we have the vector of standard deviations.Example1> M1 M1Output [, 1] [, 2] [, 3] ...

Read More

How to create a plot using rgb colors in R?

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

The rgb colors are referred to red green and blue. This combination helps us to create many different colors. In R, we can use rgb function to create a plot using with different colors along with the image function. If we want to have a plot with rgb colors without any axes title or axes labels then the appropriate arguments should be used inside the image function as shown in the below example.ExampleConsider the below data frame:> set.seed(9991) > x1 x2 x3 df dfOutput x1 x2 ...

Read More

How to remove rows based on blanks in a column from a data frame in R?

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

Sometimes data is incorrectly entered into systems and that is the reason we must be careful while doing data cleaning before proceeding to analysis. A data collector or the sampled unit might enter blank to an answer if he or she does not find an appropriate option for the question. This also happens if the questionnaire is not properly designed or blank is filled by mistake. Also, if we have categorical variable then a control category might be filled with blank or we may want to have a blank category to use a new one at later stage. Whatever the ...

Read More

How to create a bar plot using ggplot2 with one bar having black border in R?

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

The bar plot can be easily created with the help of geom_bar. But if we want to have a different border for a particular bar then we first need to create the bar plot and store it in an object. After that we need to add the original plot with the bar for which we want to have a black border. Check out the below example to understand how it can be done.ExampleConsider the below data frame:> Group Freq df dfOutput Group Freq 1 G1 18 2 G2 27 3 G3 24Loading ggplot2 package ...

Read More

How to find the column means of a column based on another column values that represent factor in an R data frame?

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

If we have a column that represent factor then we might want to find the mean of values in other column(s) for the factor levels. This is helpful in comparing the levels of the factor. In R, we can find the mean for such type of data by using aggregate function. Check out the below examples to understand how it can be done.Example1Consider the below data frame:> x1 y1 df1 df1Output x1 y1 1 D 5.801197 2 B 3.432060 3 B 6.154168 4 A 5.466655 5 D 5.171689 6 C 5.175170 7 B 5.353469 8 D 4.840470 ...

Read More
Showing 12211–12220 of 21,090 articles
Advertisements