Articles on Trending Technologies

Technical articles with clear explanations and examples

How to create a bar chart using plotly in R?

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

Plotly in R is a package specifically designed to create highly-interactive and publication-quality charts. The chart can be created by using plot_ly function of the package and there are three main arguments of plot_ly defined as x, y, and type, where x refers to the X-axis, y refers to the Y-axis and type refers to the chart type but the axes values are stored in a data frame or itself a shared.ExampleLoading plotly package:> library(plotly)Consider the below data frame:> x count df dfOutputx count 1 A 321 2 B 324 3 C 320 4 D 328Creating the bar plot for ...

Read More

Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M in C++

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

We are provided two numbers START and END to define a range of numbers.The goal is to find all the numbers in the range [START, END] which have no digit as 0 and have sum of digits equal to a given number N. Also the numbers are divisible by MWe will do this by traversing numbers from START to END and for each number we will count the sum of its digit using a while loop ( only if all digits are non zero ). If this sum is equal to N and the number is divisible by M, increment ...

Read More

How to display the curve on the histogram using ggplot2 in R?

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

Mostly, we use histogram to understand the distribution of a variable but if we have an overlay line on the histogram that will make the chart smoother, thus understanding the variation will become easy. To display the curve on the histogram using ggplot2, we can make use of geom_density function in which the counts will be multiplied with the binwidth of the histogram so that the density line will be appropriately created.ExampleConsider the below data frame:> x df head(df, 20)Output x 1 4 2 5 3 6 4 4 5 9 6 ...

Read More

How to create a vector of lists in R?

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

If we have many lists but we want to use the values in the lists as a vector then we first need to combine those lists and create a vector. This can be done by using unlist function along with the combine function c to create the vector. For example, if we have two lists defined as List1 and List2 and we want to create a vector V using these lists then it can be created as:V x1 x1Output$a [1] -0.6972237 -1.5013768 -0.2451809 -0.2365569 -1.6304919 -1.1704378 [7] 1.1617054 -0.2349498 -1.2582229 0.4112065 $b [1] 2 0 2 6 0 0 ...

Read More

Count ordered pairs of positive numbers such that their sum is S and XOR is K in C++

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

We are given two numbers S and K. The goal is to find ordered pairs of positive numbers such that their sum is S and XOR is K.We will do this by starting from i=1 to i

Read More

How to replace a sub-string with the reverse of that sub-string in R?

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

The chartr function in base R helps us to replace old strings with new strings and hence it can be also used to replace a subs-string with the reverse of that substring. For example, if we have a vector say x that contains tutorialpsoint and we want to convert it to tutorialspoint then it can be done as chartr("tutorialpsoint ", " tutorialspoint ", x).Example1> x1 x1Output[1] "IDNIA"Example> chartr("DN", "ND", x1)Output[1] "INDIA" Example2> x2 x2Output[1] "IDNIA" "IDNIA" "IDNIA" "IDNONESIA" "IDNIA" "IDNONESIA" [7] "IDNONESIA" "IDNIA" "IDNONESIA" "IDNIA" "IDNIA" "IDNONESIA" [13] "IDNONESIA" "IDNONESIA" "IDNIA" "IDNONESIA" "IDNIA" "IDNIA" [19] "IDNONESIA" "IDNONESIA" "IDNIA" "IDNONESIA" "IDNIA" ...

Read More

Count ordered pairs with product less than N in C++

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

We are given a number N. The goal is to find ordered pairs of positive numbers such that their product is less than N.We will do this by starting from i=1 to i

Read More

How to find the mean of row values in an R data frame using dplyr?

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

The mean of row values can be found by using rowwise function of dplyr package along with the mutate function to add the new column of means in the data frame. The rowwise function actually helps R to read the values in the data frame rowwise and then we can use mean function to find the means as shown in the below examples.Example1Consider the below data frame:> x1 x2 df1 df1Output x1 x2 1 0 8 2 2 3 3 2 5 4 0 5 5 3 2 6 0 10 7 3 5 8 1 7 9 0 4 ...

Read More

Count pairs (a, b) whose sum of cubes is N (a^3 + b^3 = N) in C++

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

We are given a number N. The goal is to find ordered pairs of positive numbers such that the sum of their cubes is N.We will do this by finding solutions to the equation a3 + b3 = N. Where a is not more than cube root of N and b can be calculated as cube root of (N-a3).Let’s understand with examples.Input N=35Output Count of pairs of (a, b) where a^3+b^3=N: 2Explanation Pairs will be (2, 3) and (3, 2). 23+33=8+27=35Input N=100Output Count of pairs of (a, b) where a^3+b^3=N: 0Explanation No such pairs possible.Approach used in the below program is as followsWe take integer N.Function ...

Read More

How to perform chi square test for goodness of fit in R?

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

The chi square test for goodness of fit is a nonparametric test to test whether the observed values that falls into two or more categories follows a particular distribution of not. We can say that it compares the observed proportions with the expected chances. In R, we can perform this test by using chisq.test function. Check out the below examples to understand how it is done.Example1> x1 x1Output[1] 9 4 1 9 6 6 1 6 0 0 5 8 8 3 7 8 0 3 3 9 6 0 3 8 2 0 8 5 9 1 3 4 ...

Read More
Showing 26331–26340 of 61,297 articles
Advertisements