Programming Articles

Page 1153 of 2547

How to add approximately equal sign in a plot using ggplot2 in R?

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

To add approximately equal sign in a plot using ggplot2, we can use tilde sign twice as ~~ in geom_text function of ggplot2 package. For example, we can do this by using the following syntax geom_text(aes(label="NULL%~~%")). Check out the below example to understand how it works.ExampleConsider the below data frame −x

Read More

How to create a list of regression models for predefined vectors in R?

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

To create a list of regression models for predefined vectors, we can create a blank list and then use the for loop to create the list of regression models. For example, if we have two vectors say x and y, and we want to create a list of regression model between x and y then we create a blank list using list() and perform for loop a particular number of times as shown in the below examples.Example1x

Read More

C++ program to find n-th term of series 2, 10, 30, 68, 130 ...

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 4K+ Views

In this problem, we are given an integer N. The task is to find the n-th term in series 2, 10, 30, 68, 130...Let’s take an example to understand the problem, InputN = 7Output350ExplanationThe series is 2, 10, 30, 68, 130, 222, 350...Solution ApproachA simple solution to the problem is by finding the general term of the series. Here, the Nth term of the series is N^3 + N. This is found by subtracting the current element with the current index.For i, i = 1, T(1) = 2 = 1 + 1 = 1^3 + 1 i = 2, T(1) ...

Read More

How to change the point size in geom_point conditionally in R?

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

To change the point size in geom_point conditionally, we can define the condition in geom_point with aes and the size using scale_size_manual function of ggplot2 package. For example, if we have a data frame called df that contains two columns say x and y then the scatterplot with different size of points for x values greater than 5 and less than equal to 5 can be drawn by using the below command −ggplot(df, aes(x, y))+geom_point(aes(size=x>5))+scale_size_manual(values=c(4, 7))ExampleConsider the below data frame −x6))+scale_size_manual(values=c(4, 7)) Output

Read More

C++ program to find n-th term of series 3, 9, 21, 41, 71...

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

In this problem, we are given an integer N. The task is to find the n-th term in series 3, 9, 21, 41, 71...Let’s take an example to understand the problem, InputN = 7Output169ExplanationThe series is 3, 9, 21, 41, 71, 169...Solution ApproachA simple solution to the problem is by finding the general term of the series. The general term can be found by observing the series a bit. It is, $$T(N) = \sum n^{2} + \sum n + 1$$We can directly use the formula for the sum of square of first n natural numbers, first n natural number and ...

Read More

How to find the proportion of each value for a cross tab obtained from a data frame in R?

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

To find the proportion of each value for a cross tab obtained from a data frame, we can use prop.table function. Suppose we have a data frame called df that contains three columns, two categorical say C1 and C2 and one numerical say Y then the cross tab will be created by using the command xtabs(Y~.,df). Now the proportion of each value can be found by using prop.table(xtabs(Y~.,df),1).Example1Consider the below data frame −f1

Read More

Find n-variables from n sum equations with one missing in C++

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

In this problem, we are given an array sum[] consisting of a sum of (n-1) variables given as, Sum[1] = x2 + x3 + x4 + … xn Sum[2] = x1 + x3 + x4 + … xn . . Sum[i] = x2 + x3 + x4 + … x(i-1) + x(i+1) + … + xn . . Sum[n] = x1 + x2 + x3 + … x(n-1) Our task is to find the value of x1, x2, ... xn.Let’s take an example to understand the problem, Inputsum[] = {6, 6, 6, 6, 6, 6, 6}Outputx1 = 1, x2 = ...

Read More

How to change default point size of geom_point in R?

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

To change the default point size of geom_point, we need to use update_geom_defaults function. Specifically, for the change of point size the syntax will be as follows −update_geom_defaults("point",list(size=”value”))Here, we can change the value according to our need.ExampleConsider the below data frame −x

Read More

Find N'th item in a set formed by sum of two arrays in C++

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

In this problem, we are given two sorted arrays arr1[] and arr2[] of size m and an element N. Our task is to Find Nth item in a set formed by the sum of two arrays.Code description − Here, we will create a set that consists of the sum of element one of arr1 and one of arr2 i.e. sum = arr1[i] + arr2[j], where are i , j < m. For N, we need to find the value of the Nth element of the set.Let’s take an example to understand the problem, Inputarr1[] = {3, 1, 5} , arr2[] = ...

Read More

How to create data frame using nested list elements in R?

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

To create data frame using nested list elements, we would need to unlist the list elements and store them in a matrix then read as a data frame using data.frame function. For example, if we have a nested called LIST then the data frame can be created by using the command −data.frame(matrix(unlist(LIST),ncol=”No of columns we want”,byrow=F))Check out the below example to understand how it works.ExamplenestedList

Read More
Showing 11521–11530 of 25,466 articles
Advertisements