Programming Articles - Page 918 of 3363

How to display data frame name in ggplot2 graph title in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 07:57:14

626 Views

To display data frame name in ggplot2 graph title, we can use ggtitle function and pass the name of the data frame.For example, if we have a data frame called df that contains two columns say x and y and we can create a point chart between x and y then the plot with data frame name as title can be created by using the below mentioned command −ggplot(df,aes(x,y))+geom_point()+ggtitle("df")ExampleFollowing snippet creates a sample data frame −x

How to create a colored frame for ggplot2 graph in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 07:55:01

315 Views

To create a colored frame for ggplot2 graph, we can use theme function and set the plot.background argument to different color for rectangular element.For example, if we have a data frame called df that contains two columns say X and Y then we can create point chart between X and Y with blue colored frame of the plot using the below mentioned command −ggplot(df,aes(X,Y))+geom_point()+theme(plot.background=element_rect(colour="blue",size=3))ExampleFollowing snippet creates a sample data frame −x

Recursive function to check if a string is palindrome in C++

Sunidhi Bansal
Updated on 02-Nov-2021 08:09:17

6K+ Views

We are given a string Str as input. The goal is to find if the input string is a palindrome word or not using a recursive function. Palindrome strings are those strings that when read from front or end form the same word. The strings of length 0 are considered as palindromes. Reversing the palindromes character wise forms, the same string as the original.Examples of palindromes are:- madam, abcba, malayalam etcExamplesInput − Str = “malayalam”Output − Input string is palindrome.Explanation −Str[ 0 to 8 ] = malayalamReverse Str [ 8 to 0 ] = malayalamBoth strings are same.Input − Str = “tutorial”Output − Input string ... Read More

How to add title to regression model using stargazer in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 07:52:04

1K+ Views

To add title to regression model using stargazer, we can use title argument inside stargazer function.For example, if we have a model called Reg_Model with Output as text then the title to this model using stargazer can be added by using the below mentioned command −stargazer(Reg_Model,type="text",title="Regression Model between x and y")Example 1Following snippet creates a sample data frame −x

How to delete a row from an R data frame if any value in the row is greater than n?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 07:45:00

6K+ Views

To delete a row from an R data frame if any value in the row is greater than n can be done by using the subsetting with single square brackets and negation operator. We will subset the values that are greater than n and then take the negation of the subset as shown in the below given examples.Example 1Following snippet creates a sample data frame −x1

Check if any value in an R vector is greater than or less than a certain value.

Nizamuddin Siddiqui
Updated on 02-Nov-2021 07:55:05

11K+ Views

To check if any value in an R vector is greater than or less than a certain value, we can use any function.For Example, if we have a vector called V and we want to check if any value in V is greater than 100 then we can use the command given below −any(V>100)Similarly, we can check if any value is less than 100 by using the command as follows −any(V

C Program for Recursive Bubble Sort

Sunidhi Bansal
Updated on 02-Nov-2021 07:58:22

9K+ Views

Bubble Sort is one of the simplest sorting algorithms used to sort data by comparing the adjacent elements. All the elements are compared in phases. The first phase places the largest value at the end, the second phase places the second largest element at the second last position and so on till the complete list is sorted.Bubble Sort Algorithmint arr[5]= { 5, 4, 2, 1, 3 };int i, j ;Traverse from index i=0 to iarr[j] swap arr[i] with arr[j]EndRecursive Bubble SortIf array length is 1 then returnTraverse array once and fix largest element at the endRecursively perform step 2 for ... Read More

How to find the sum product of two matrix by row in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 07:39:45

782 Views

To find the sum product of two matrix by row in R, we can use rowSums function by passing the multiplication of the matrices.For example, if we have two matrices say Matrix1 and Matrix2 then, the sum product of these two matrices by row can be found by using the following command −rowSums(Matrix1*Matrix2)Example 1Following snippet creates a matrix −M1

How to multiply each value in a column by a constant in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 07:33:26

10K+ Views

To multiply each value in a column by a constant, we can use multiplication sign *.For example, if we have a data frame called df that contains a column say x. Now, if we want to multiply each value in x with 10 then we can use the below mentioned command −df$x

Rearrange the given source code in C++

Sunidhi Bansal
Updated on 02-Nov-2021 07:37:58

418 Views

We are given a string type variable, let's say, str which will be used to store the source code then calculate the size of the string and pass it to the function. The task is to rearrange the given source code and then print the result.Let us see various input output scenarios for this −Input − string str ="#include using namespace std; int main()"    "{ int sum, first, second; sum = first + second; printf(\"%d\", c);"    " return 0;}"Output −#include using namespace std; int main(){    int sum, first, second;    sum = first + second;    printf("%d", ... Read More

Advertisements