Articles on Trending Technologies

Technical articles with clear explanations and examples

How to select the first and last row based on group column in an R data frame?

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

Extraction of data is necessary in data analysis because extraction helps us to keep the important information about a data set. This important information could be the first row and the last row of groups as well, also we might want to use these rows for other type of analysis such as comparing the initial and last data values among groups. We can extract or select the first and last row based on group column by using slice function of dplyr package.ExampleConsider the below data frame: > x1 x2 df1 head(df1, 12)Output  x1 x2 1  1  3 2  1  4 ...

Read More

Maximum product of an increasing subsequence in C++

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

In this tutorial, we will be discussing a program to find maximum product of an increasing subsequence.For this we will be provided with an array of integers. Our task is to find the maximum product of any subsequence of the array with any number of elements.Example#include #define ll long long int using namespace std; //returning maximum product ll lis(ll arr[], ll n) {    ll mpis[n];    //initiating values    for (int i = 0; i < n; i++)       mpis[i] = arr[i];    for (int i = 1; i < n; i++)       for ...

Read More

Sum of the series 2 + (2+4) + (2+4+6) + (2+4+6+8) + ... + (2+4+6+8+...+2n) in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 422 Views

In this problem, we are given a number n which defines the nth term of the series 2 + (2+4) + (2+4+6) + (2+4+6+8) + ... + (2+4+6+8+...+2n). Our task is to create a program to find the sum of the series.Let’s take an example to understand the problem,Input n = 3OutputExplanation − sum = (2) + (2+4) + (2+4+6) = 2 + 6 + 12 = 20A simple solution to the problem is to use a nested loop. The inner loop finds the ith element of the series and then add up all elements to the sum variable.ExampleProgram to illustrate the working of our solution,#include using namespace std; int calcSeriesSum(int n) {    int sum = 0;    for (int i = 1; i

Read More

Maximum product of indexes of next greater on left and right in C++

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

In this tutorial, we will be discussing a program to find maximum product of indexes of next greater on left and right.For this we will be provided with an array of integers. Our task is to find the element with maximum Left-Right product (L(i)*R(i) where L(i) is closest index on left side and greater than current element and R(i) is closest index on right side and greater than current element).Example#include using namespace std; #define MAX 1000 //finding greater element on left side vector nextGreaterInLeft(int a[], int n) {    vector left_index(MAX, 0);    stack s;    for (int i ...

Read More

How to change the background color of a plot created by using plot function in R?

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

To change the focus of a plot we can do multiple things and one such thing is changing the background of the plot. If the background color of a plot is different than white then obviously it will get attention of the readers because this is unusual as most of the times the plots have white backgrounds, hence if we want to attract readers on the plot then we might use this technique. It can be done by using par(bg= "color_name").ExampleCreating a simple histogram −> x hist(x)OutputExampleCreating histogram with different background colors −> par(bg="green") > hist(x)Output> par(bg="yellow") > hist(x)Outputpar(bg="blue") > ...

Read More

How to add a new column to represent the percentage for groups in an R data frame?

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

In data analysis, we often need to find the percentage of values that exists in a data group. This helps us to understand which value occurs frequently and which one has low frequency. Also, plotting of percentages through pie charts can be done and that gives a better view of the data to the readers. Adding a new column as percentage for groups is not a challenge if we can use mutate function of dplyr package, here you will get the examples from that.Example1> Gender Salary df2 df2Output Gender  Salary 1  Male   41734 2  Male   39035 3  Male   ...

Read More

How to find the mean of corresponding elements of multiple matrices in R?

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

If the elements of multiple matrices represent the same type of characteristic then we might want to find the mean of those elements. For example, if we have matrices M1, M2, M3, and M4 stored in a list and the first element represent the rate of a particular thing, say Rate of decay of rusty iron during rainy season, then we might want to find the mean of first element of matrix M1, M2, M3, and M4. This mean can be found by using Reduce function.ExampleConsider the below matrices and their list −> M1 M1Output   [, 1] [, 2] [, ...

Read More

Maximum sum of increasing order elements from n arrays in C++

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

In this tutorial, we will be discussing a program to find maximum sum of increasing order elements from n arrays.For this we will be provided with N arrays of M size. Our task is to find the maximum sum by selecting one element from each array such that element from the previous array is smaller than the next one.Example#include #define M 4 using namespace std; //calculating maximum sum by selecting //one element int maximumSum(int a[][M], int n) {    for (int i = 0; i < n; i++)       sort(a[i], a[i] + M);    int sum = ...

Read More

Java Program for Longest Palindromic Subsequence

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 367 Views

For longest Palindromic subsequence, the Java code is as follows −Examplepublic class Demo{    static String longest_seq(String str_1, String str_2){       int str_1_len = str_1.length();       int str_2_len = str_2.length();       char str_1_arr[] = str_1.toCharArray();       char str_2_arr[] = str_2.toCharArray();       int L[][] = new int[str_1_len + 1][str_2_len + 1];       for (int i = 0; i 0){          if (str_1_arr[i - 1] == str_2_arr[j - 1]){             longest_seq[my_index - 1] = str_1_arr[i - 1];         ...

Read More

How to add a new column in an R data frame by combining two columns with a special character?

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

A data frame can have multiple types of column and some of them could be combined to make a single column based on their characteristics. For example, if a column has characters and the other has numbers then we might want to join them by separating with a special character to showcase them as an identity.ExampleConsider the below data frame −> ID Frequency set.seed(111) > ID Frequency df dfOutput   ID Frequency 1 A    78 2 B    84 3 C    83 4 D    47 5 E    25 6 F    59 7 G    69 8 ...

Read More
Showing 26761–26770 of 61,298 articles
Advertisements