Programming Articles

Page 1171 of 2547

How to check if two matrices are equal in R?

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

When we matrices of larger size and the data is expected to from the same distribution or from same sources then we might expect that the matrices are equal. In this type of situations, we would like to check whether the two matrices are equal or not. This can be done with the help of all.equal function as shown in the below examples.ExampleM1

Read More

How to sort an R data frame column without losing row names?

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

When we sort a data frame column in R, the row names are lost but we might need them. Therefore, sorting without losing row names is required and it can be done with the help of order function. For example, if we have a data frame called df that has a column x then sorting of x without losing row names can be done by using the below command −df[order(df$x),,drop=FALSE]Consider the below data frame −Examplex1

Read More

Find a peak element in Linked List in C++

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

In this tutorial, we are going to write a program that finds the peak element in the given linked list.The peak element is an element that is greater than the surrounding elements. Let's see the steps to solve the problem.Create a struct node for the linked list.Create the linked list with dummy data.Check for the base cases like whether the linked list is empty or of length 1.Store the first element in a variable called previous.Iterate over the linked list.Check whether the current element is greater than the previous element and the next element.Return if the above condition satisfies.Update the ...

Read More

How to find the column index in an R data frame that matches a condition?

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

To find the column index that matches a condition, we can use apply function. This condition could be values in columns greater than something, less than something, equal to something, or any other condition for numerical variables. For example, if we want to check which columns of data df contains value in rows greater than 5 then we can use the command apply(df,1, function(x) which(x>5)).Consider the below data frame −Examplex1

Read More

How to extract first value from a list in R?

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

To extract first value from a list, we first need to access the element using double square brackets then the sub-element of each element will be accessed using single square brackets. For example, if we have a list called LIST containing five elements each having 10 elements then the first sub-element of the LIST will be selected by using LIST[[1]][1].ExampleList1

Read More

Find a peak element in C++

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

In this tutorial, we are going to write a program that finds the peak element in the given arrayThe peak element is an element that is greater than the surrounding elements. Let's see the steps to solve the problem.Initialize the array with dummy data.Check for the first element and last element for the peak element condition.Iterate over the array from the second element.Check whether the current element is greater than the previous element and the next element.Return if the above condition satisfies.Print the resultExampleLet's see the code.#include using namespace std; int findPeakElement(int arr[], int n) {    if (n ...

Read More

How to remove single quote from string column in an R data frame?

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

Sometimes column values in an R data frame have single quote associated with them and to perform the analysis we need to remove that quote. Therefore, to remove single quote from string column, we can use gsub function by defining the single quote and replacing it with blank(not space) as shown in the below examples.Consider the below data frame −Examplex1

Read More

Find a triplet from three linked lists with a sum equal to a given number in C++

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

In this tutorial, we are going to write a program that finds the triplet in the linked list whose sum is equal to the given number.Let's see the steps to solve the problem.Create a struct node for the linked list.Create the linked list with dummy data.Write three inner loops for three elements which iterate until the end of the linked list.Add the three elements.Compare the sum with the given number.If both are equal, then print the elements and break the loops.ExampleLet's see the code.#include using namespace std; class Node {    public:    int data;    Node* next; }; ...

Read More

Find a triplet that sum to a given value in C++

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

In this tutorial, we are going to write a program that finds the triplet in the array whose sum is equal to the given number.Let's see the steps to solve the problem.Create the array with dummy data.Write three inner loops for three elements which iterate until the end of the array.Add the three elements.Compare the sum with the given number.If both are equal, then print the elements and break the loops.ExampleLet's see the code.#include using namespace std; bool findTriplet(int arr[], int arr_size, int sum) {    for (int i = 0; i < arr_size - 2; i++) {   ...

Read More

How to sort matrix columns independently in increasing order in R?

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

To sort a matrix column independently in increasing order means that ordering each column of the data frame in increasing order, therefore, sorting of values in one column does not affect the sorting in other columns. This can be done with the help of apply function along with the sort function as shown in the below examples.ExampleM1

Read More
Showing 11701–11710 of 25,466 articles
Advertisements