Programming Articles

Page 130 of 2544

How to create group names for consecutively duplicate values in an R data frame column?

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

The grouping of values can be done in many ways and one such way is if we have duplicate values or unique values then the group can be set based on that. If all the values are unique then there is no sense for grouping but if we have varying values then the grouping can be done. For this purpose, we can use rleid function as shown in the below examples.Example1Consider the below data frame −> x df1 df1Output x 1 2 2 1 3 2 4 2 5 1 6 0 ...

Read More

Different substrings in a string that start and end with given strings in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 368 Views

In this tutorial, we are going to write a program that finds the total number of substrings that starts and ends with the given strings.We are given one string and two substrings. We need to find the different substrings count that starts and ends with the given two substrings. Let's see an example.Inputstr = "getmesomecoffee" start = "m" end = "e"Output6There are a total of 6 different substrings in the given string. They are me, mesome, mesomemecoffe, mesomemecoffee, mecoffe, mecoffee.Let's see the steps to solve the problem.Initialize the strings.Iterate over the str and find the start and end substrings indexes. ...

Read More

How to use pnorm function on data frame columns in R?

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

The pnorm function is used to find the probability for a normally distributed random variable. Probabilities such as less than mean, greater than mean, or probability between left- and right-hand side of the mean. If we want to use pnorm function on data frame columns then apply function can help us.Consider the below data frame −Examplex1

Read More

Digital Root (repeated digital sum) of the given large integer in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 1K+ Views

In this tutorial, we are going to learn how to find the digital root of a given number.The digital root is the sum of a number of digits (until the sum of the digits becomes a single digit).We are given an integer in string format. And we have to find the sum of the digits repeatedly until the sum becomes a single digit.Let's see the steps to solve the problem.Initialize an integer in the string format.Iterate through the number and add each digit to the sum variable.If the sum is 0, then print 0.Else if the sum is divisible by ...

Read More

Sort an arrays of 0’s, 1’s and 2’s using C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 11-Mar-2026 1K+ Views

Given an array of 0, 1, and 2, sort the elements in an order such that all the zeros come first before 1 and all the 2’s in the end. We have to sort all the elements of the array in-place.We can solve this problem using DNF (Dutch National Flag) Sorting Algorithm. For example, Input-1 −arr[ ]= {2, 0, 0, 1, 2, 1 }Output −0 0 1 1 2 2Explanation − Sorting the given array of elements containing 0, 1 and 2 using DNF Sorting Algorithm, it will print the output as {0, 0, 1, 1, 2, 2}.Input-2 −arr[ ]= ...

Read More

Digits of element wise sum of two arrays into a new array in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 326 Views

In this tutorial, we are going to write a program that finds the sun of two array elements and store them into a separate array.We have given two arrays and we need to add the corresponding index elements from the two arrays. If the sum is not single digits, then extract the digits from the number and store them in the new array.Let's see an example.Inputarr_one = {1, 2, 32, 4, 5} arr_two = {1, 52, 3}Output2 5 4 3 5 4 5Let's see the steps to solve the problem.Initialize two arrays with dummy data.We are using the vector to ...

Read More

Sort an arrays of 0’s, 1’s and 2’s using Java

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 11-Mar-2026 487 Views

Given an array of 0, 1 and 2 sort the element in an order such that all the zeros come first before 1 and all the 2’s in the end. We have to sort all the elements of the array in-place.We can solve this problem using DNF (Dutch National Flag) Sorting Algorithm. For example, Input-1 −arr[ ]= {2, 0, 0, 1, 2, 1 }Output −0 0 1 1 2 2Explanation − Sorting the given array of elements containing 0, 1 and 2 using the DNF Sorting Algorithm, it will print the output as {0, 0, 1, 1, 2, 2}.Input-2 −arr[ ...

Read More

How to remove spaces at the end in string vectors in R?

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

Sometimes values in a string vector has an extra space at the end, this might happen while typing the values or due to some other manual errors. To remove spaces at the end in string vectors, we can use gsub function. For example, if we have a vector called x that contains string values with spaces at the end then the removal of values can be done by using the command gsub(" $","",x,perl=T)Examplex1

Read More

Square of a sorted array in C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 11-Mar-2026 2K+ Views

In the given array of sorted integers, the task is to print the squares of every array element and print the array in sorted order. For example, Input-1 −arr[ ] = { -3, -1, 0, 1, 4, 6 };Output −{0, 1, 1, 9, 16, 36}Explanation − The squares of each of the elements of the given array [-3, -1, 0, 1, 4, 6 ] is [0, 1, 1, 9, 16, 36 ].Input-2 −arr[ ]= { 0, 1, 2, 8, 9 }Output −{0, 1, 4, 64, 81}Explanation − The squares of each of the elements of the given array [ 0, ...

Read More

How to find the rate of return for a vector values in R?

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

To find the rate of return for a vector values, we can use the formula for rate of return. For example, if we have a vector called x then the rate of return can be calculated by using the syntax diff(x)/x[-length(x)]. The output will be in decimal form and if we want to convert it to percentage then the output needs to be multiplied with 100, we can also input the same within the formula as (diff(x)/x[-length(x)])*100.Examplex1

Read More
Showing 1291–1300 of 25,433 articles
« Prev 1 128 129 130 131 132 2544 Next »
Advertisements