Found 26504 Articles for Server Side Programming

Recursive Programs to find Minimum and Maximum elements of array in C++

Sunidhi Bansal
Updated on 03-Nov-2021 05:07:30

13K+ Views

We are given an integer array Arr[] as input. The goal is to find maximum and minimum elements among the array using recursive methods.Since we are using recursion, we will traverse the whole array till we reach length=1 then return A[0] which forms the base case. Else compare current element with present minimum or maximum and update its value by recursion for later elements.Let us see various input output scenarios for this −Input − Arr= {12, 67, 99, 76, 32};Output − Maximum in the array :99Explanation − Out of all elements 99 is maximum among them.Input − Arr= {1, 0, -99, 9, 3};Output − Minimum ... Read More

Recursive Program for Binary to Decimal in C++

Sunidhi Bansal
Updated on 03-Nov-2021 05:03:49

2K+ Views

We are given a string containing a binary number. The goal is to find the equivalent decimal number using the recursive method.A binary number can be converted to decimal using following method-: Traverse from LSB to MSB and multiply each with power of 2i Where 0

How to add zero before a vector in R?

Nizamuddin Siddiqui
Updated on 03-Nov-2021 05:04:49

558 Views

To add zero before a vector in R, we can simply use rep function and provide the number times we want to have zero in the vector.For Example, if we have a vector called X that contains three values say 1, 2, 3 and we want to add three zeros before this vector then we can use the command as given below −X

Fill bars in a base R barplot with colors based on frequency.

Nizamuddin Siddiqui
Updated on 03-Nov-2021 05:00:31

473 Views

Suppose we have a vector that contains only frequencies and we want to create a bar chart in base R using these frequencies with color of bars based on frequencies, therefore, we can use barplot function and providing the color of the bars with as shown in the below ExamplesThe function is as follows −heat.colors functionExample 1To fill the bars in a base R barplot with colours based on frequency, use the command given below −Frequency_1

How to create a circle filled with a color in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 12:07:41

954 Views

We can create a circle in R by using draw.circle function of plotrix package and default color of the circle is white. If we want to change the color of a circle then we can use col argument and pass the desired colors.For Example, if we want to create a blue colored circle then we can use the command given below −draw.circle(5, 5, 2, col="blue")Check out the below Example to understand how it works.ExampleTo create a circle filled with a colour, use the command given below −plot(1:10, type="n") OutputIf you execute the above command, it generates the following Output −To ... Read More

How to change a text value in an R data frame?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 11:57:50

3K+ Views

To change a text value in an R data frame, we can simply use replace function.For Example, if we have a data frame called df that contains a column say Names and one of the names say Raj is misspelled as Raaj then we can replace Raaj with Raj by using the command given below −df$Names

How to find mathematical set using a data frame column in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 11:45:44

121 Views

A mathematical set is a collection of unique elements or a collection of elements that are different from each other. If we want to find a mathematical set using a data frame column then we can simply use unique function.For Example, if we have a data frame called df that contains a column say X then we can find the mathematical set using X with the help of below command −unique(df$X)Example 1Following snippet creates a sample data frame −x

How to change the color of gridlines of a ggplot2 graph in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 11:32:22

4K+ Views

To change the color of gridlines of a ggplot2 graph in R, we can use theme function with panel.grid.major and panel.grid.minor arguments where we can set the minor and major gridlines color of the plot panel to desired color.To understand how it can be done, check out the below Example.ExampleFollowing snippet creates a sample data frame −x

How to change the plot border color of a ggplot2 graph in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 11:25:46

5K+ Views

To change the plot border color of a ggplot2 graph in R, we can use theme function with panel.background argument where we can set the border of the plot panel using element_rect to desired color.To understand how it can be done, check out the below Example.ExampleFollowing snippet creates a sample data frame −x

Find the sum of a column values based on another numerical column in R.

Nizamuddin Siddiqui
Updated on 02-Nov-2021 11:16:35

552 Views

To find the sum of a column values based on another numerical column in R, we can use with function and define the sum by subsetting the column with the help of single square brackets.For Example, if we have a data frame called df that contains two columns say X and Y then we can find the sum of values in X when Y is greater than 10 by using the command with the following −(df,sum(X[Y10]))Example 1Following snippet creates a sample data frame −x1

Advertisements