Articles on Trending Technologies

Technical articles with clear explanations and examples

How to change the row index after sampling an R data frame?

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

When we take a random sample from an R data frame the sample rows have row numbers as in the original data frame, obviously it happens due to randomization. But it might create confusion while doing analysis, especially in cases when we need to use rows, therefore, we can convert the index number of rows to numbers from 1 to the number of rows in the selected sample.ExampleConsider the below data frame −> set.seed(111) > x1 x2 x3 df1 df1Output      x1          x2       x3 1 1.735220712 2.8616625 1.824274 2 1.169264128 2.8469644 1.878784 ...

Read More

Examples of soft references and phantom references?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 400 Views

Soft references are often used to implement memory-sensitive caches. Let us see an example of soft references in Java −Exampleimport java.lang.ref.SoftReference; class Demo{    public void display_msg(){       System.out.println("Hello there");    } } public class Demo_example{    public static void main(String[] args){       Demo my_instance = new Demo();       my_instance.display_msg();       SoftReference my_softref = new SoftReference(my_instance);       my_instance = null;       my_instance = my_softref.get();       my_instance.display_msg();    } }OutputHello there Hello thereA class named Demo contains a function named ‘display_msg’, that displays the relevant message. Another ...

Read More

Count valid pairs in the array satisfying given conditions in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 727 Views

We are given with an array arr[] of N elements. The goal is to find the count of all valid pairs (Arr[i],Arr[j]) that follow certain conditions. Pairs Arr[i],Arr[j] invalid if −Arr[i]==Arr[j]Arr[i]+Arr[j] is eveni+j

Read More

How to find standard deviations for all columns of an R data frame?

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

To find the means of all columns in an R data frame, we can simply use colMeans function and it returns the mean. But for standard deviations, we do not have any direct function that can be used; therefore, we can use sd with apply and reference the columns to find the standard deviations for all column of an R data frame. For example, if we have a data frame df then the syntax using apply function to find the standard deviations for all columns will be apply(df, 2, sd), here 2 refers to the columns. If we want to ...

Read More

Maximum number of groups of size 3 containing two type of items in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 325 Views

Given the task is to calculate the maximum number of groups of size 3 that can be formed when N number of items of type A and M number of items of type B are given.Also, each group should have at least one item of each type, that is either A or B.Let’s now understand what we have to do using an example −Input − N=3, M=5Input − 2ExplanationGroup 1: 1 item of type A and 2 items of type B Group 2: 1 item of type A and 2 items of type B In total, 2 items of type ...

Read More

Count ways of choosing a pair with maximum difference in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 493 Views

We are given with an array of numbers Arr[]. The goal is to count the number of pairs whose difference is equal to the maximum difference of all possible pairs. Count pairs (i!=j) and arr[x]- arr[y] is maximum possible.We will do this by first finding the maximum difference where (i!=j). And store as maxdiff. Then count all those pairs that have difference=maxdiff.Let’s understand with examples.Input − arr[]= { 1, 2, 3, 2, 4, 1, 5 }Output − No. of ways of choosing pair with maximum difference − 2Explanation −Here minimum no. is 1 and maximum number is 5, maximum difference ...

Read More

How to change the gridlines of Y-axis on a chart created by using ggplot2 in R?

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

Normally, the gridlines on a plot created by using ggplot2 package are a little far from each other but sometimes the plot looks better if the gridlines are close to each other, therefore, we might want to do so. This can be done by setting the minor_breaks and breaks using scale_y_continuous if the Y-axis plots a continuous variable.ExampleConsider the below data frame −> x y df dfOutput   x  y 1 14 16 2 36 1 3 78 18 4 61 6 5 19 11 6 2 40 7 93 23 8 10 13 9 3 21 10 55 31 11 ...

Read More

Place an H1 element and its text at a particular index in jQuery

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 692 Views

To set an element and it’s text, use the text() method in jQuery. With that, use the :nth-child selector to place it at a particular position. Following is the code −Example Document JavaScript MySQL MongoDB Java C#    $('h1:nth-child(4)').text("Python"); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −

Read More

Count the triplets such that A[i] < B[j] < C[k] in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 579 Views

We are given with three arrays A[], B[] and C[]. The goal is to find all triplets of elements of these arrays such that A[i]

Read More

Count total divisors of A or B in a given range in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 516 Views

We are given four integers L, R, A and B. The goal is to find the count of numbers in range [L, R] that fully divide either A or B or both.We will do this by traversing from L to R and for each number if number%A==0 or number%B==0 then increment count of divisors.Let’s understand with examples.Input − L=10, R=15, A=4, B=3Output − Count of divisors of A or B − 2Explanation −Number 12 is fully divisible by 3 and 4. Number 15 is fully divisible by 3 only. Total divisors=2Input − L=20, R=30, A=17, B=19Output − Count of divisors ...

Read More
Showing 26821–26830 of 61,299 articles
Advertisements