Programming Articles

Page 1233 of 2547

How to convert a data frame column to date that contains integer values in R?

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

If we have an integer column that actually contains date values, for example having 29th September 2020 as 20200929 then we can convert it to date by using transform function by reading the dates with as.Date function but as.character will also be needed so that as.Date function can read the date values.Example1S.NO

Read More

Construct Binary Tree from String in C++

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

Suppose we have a string consisting of parenthesis and integers. We have to construct a binary tree from that string. The whole input represents a binary tree. It holds an integer that followed by zero, one or two pairs of parentheses. The integer represents the root's value and a pair of parenthesis contains a child binary tree with the same structure.So, if the input is like "4(2(3)(1))(6(5))", then the output will be [3, 2, 1, 4, 5, 6] (inorder traversal)To solve this, we will follow these steps −Define a function solve(), this will take s, idx, if idx >= size ...

Read More

Output Contest Matches in C++

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

Suppose we have n teams and we always arrange the rather strong team to play with the rather weak team, like make the rank 1 team play with the team with rank n, this strategy is to make the contest more interesting. Now we have to find their final contest matches in the form of a string.These teams are given in the form of positive integers from 1 to n, which represents their initial rank. So, rank 1 is the strongest team, and Rank n is the weakest team. We will use parentheses and commas to represent the contest team ...

Read More

How to find the frequency of a particular string in a column based on another column in an R data frame using dplyr package?

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

When we have two or more categorical columns in an R data frame with strings as level of the categories or numbers as strings/integers then we can find the frequency of one based on another. This will help us to identify the cross-column frequencies and we can understand the distribution of one categorical based on another column. To do this with dplyr package, we can use filter function.ExampleClass%filter(Class=="First")%>%count(Gender) Gender n 1 Female 2 2 Male 2 df2%>%filter(Class=="Second")%>%count(Gender) Gender n 1 Female 6 2 Male 2

Read More

Boundary of Binary Tree in C++

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

Suppose we have a binary tree, we have to find the values of its boundary in anti-clockwise direction starting from root. Here boundary includes left boundary, leaves, and the right boundary in order without duplicate nodes.The left boundary is the path from root to the left-most node.The Right boundary is the path from root to the right-most node.When the root doesn't have left subtree or right subtree, then the root itself is left boundary or right boundary.So, if the input is likethen the output will be [1, 2, 4, 7, 8, 9, 10, 6, 3]To solve this, we will follow ...

Read More

Split Array with Equal Sum in C++

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

Suppose we have an array with n integers, we have to find if there are triplets (i, j, k) which follows these conditions −0 < i, i + 1 < j, j + 1 < k < n - 1Sum of subarrays (0, i - 1), (i + 1, j - 1), (j + 1, k - 1) and (k + 1, n - 1) will be same.The subarray (L, R) is a slice of the original array starting from the element indexed L to the element indexed R.So, if the input is like [1, 2, 1, 2, 1, 2, ...

Read More

How to generate the permutation of x values in y positions with fixed row sums in R?

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

To generate a permutation of x values in y positions, we can use expand.grid function. For example, if we want to generate three columns for the range of values 0 to 5 then it can be done in R by using the below command −x

Read More

How to remove rows that contains all zeros in an R data frame?

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

Often, we get missing data and sometimes missing data is filled with zeros if zero is not the actual range for a variable. In this type of situations, we can remove the rows where all the values are zero. For this purpose, we can use rowSums function and if the sum is greater than zero then keep the row otherwise neglect it.Example1y1

Read More

Split Concatenated Strings in C++

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

Suppose we have a list of strings, we can concatenate these strings together into a loop, where for each string we can choose to reverse it or not. Among all of the possible loops, we need to find the lexicographically largest string after cutting the loop, which will make the looped string into a regular one. Specifically, to find the lexicographically largest string, we need to experience two phases −Concatenate all the strings into one loop, where we can reverse some strings or not and connect them in the same order as given.Cut and make one cutting point in any ...

Read More

How to create stacked barplot using barplot function in R?

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

To create a stacked barplot using barplot function we need to use matrix instead of a data frame object because in R barplot function can be used for a vector or for a matrix only. We must be very careful if we want to create a stacked bar plot using barplot function because bar plots are created for count data only. Here, you will see some examples of count as well as continuous data, carefully read the graphs and understand how the graphs are different from each other.Example1M1

Read More
Showing 12321–12330 of 25,466 articles
Advertisements