Found 26504 Articles for Server Side Programming

How to create horizontal line in xyplot in R?

Nizamuddin Siddiqui
Updated on 02-Nov-2021 11:03:24

737 Views

To create horizontal line in xyplot, we can use abline function.For Example, if we have a data frame called df that contains two columns say X and Y and we want to create a scatterplot between X and Y using xyplot with a horizontal line at Y = 2 then we can use the command given below −xyplot(Y~X,df,abline=c(h=2))ExampleFollowing snippet creates a sample data frame −x

R Programming to find the column name for row maximum in a data.table object.

Nizamuddin Siddiqui
Updated on 02-Nov-2021 10:49:43

444 Views

If we have a data.table object and we want to find the column name for row maximum then we can use max.col function.For Example, if we have a data.table object called DT then we can find the column name for row maximum by using the below command −DT[,names(.SD)[max.col(.SD,ties.method="first")]]Example 1Following snippet creates a sample data frame −x1

Remove rows from a data frame that exists in another data frame in R.

Nizamuddin Siddiqui
Updated on 02-Nov-2021 10:34:33

6K+ Views

To remove rows from a data frame that exists in another data frame, we can use subsetting with single square brackets. This removal will help us to find the unique rows in the data frame based on the column of another data frame.Check out the below Examples to understand how it can be done.Example 1Following snippet creates a sample data frame −x

Add values in sequence to the previous value with a constant.

Nizamuddin Siddiqui
Updated on 02-Nov-2021 10:15:59

581 Views

To add values in sequence to the previous value with a constant, we can find the cumulative sum of values and add the constant to the Output.For Example, if we have a vector called X and we want to add values in X in sequence to the previous value with a constant say 10 then we can use the command given below −10+cumsum(X)Example 1Following snippet creates a sample data frame −x1

Create cross tabulation for three categorical columns in an R data frame.

Nizamuddin Siddiqui
Updated on 02-Nov-2021 10:00:04

2K+ Views

To create cross tabulation for three categorical columns, we can use xtabs function. The xtabs function will create contingency table for each category in two columns and each contingency table will be created for the category in the third column.Check out the below Examples to understand how it can be done.Example 1Following snippet creates a sample data frame −df1

R Programing to change the name of column variable and row variable in xtab table.

Nizamuddin Siddiqui
Updated on 02-Nov-2021 09:44:48

463 Views

To change the name of column variable and row variable in xtab table, we can use setNames function.For Example, if we have a xtab table called XTAB and we want to change the column variable name C and row variable name R then we can use the below command −dimnames(XTAB)

Recursive program to print formula for GCD of n integers in C++

Sunidhi Bansal
Updated on 02-Nov-2021 08:29:54

227 Views

We are given an integer as input. The goal is to print the formula of GCD of n numbers using recursion.We know that the GCD of three numbers say a1, b1 and c1 will be gcd(a1, gcd(b1, c1)).Similarly for more than three numbers, gcd can be obtained by formula as gcd ( a1, gcd(b1, gcd(c1….., gcd(y1, z1)).ExamplesInput − Num = 4;Output − Formula is:GCD(int a3, GCD(int a2, GCD(int a1, int b1)))Input − Num = 6;Output − Formula is: GCD(int a5, GCD(int a4, GCD(int a3, GCD(int a2, GCD(int a1, int b1)))))Approach used in the below program is as followsIn this approach we are using the ... Read More

Recursive program to check if number is palindrome or not in C++

Sunidhi Bansal
Updated on 02-Nov-2021 08:28:12

6K+ Views

We are given an integer as input. The goal is to find whether the input number Num is a palindrome or not using recursion.To check if a number is palindrome, reverse that number and check if both numbers are the same or not. If the reversed number is equal to the original number, then it is palindrome.ExamplesInput − Num = 34212;Output − 34212 is not a Palindrome!Explanation − If we reverse 34212 then we get 21243. 34212 != 21243 hence the input number is not palindrome.Input − Num = 32123;Output − 32123 is Palindrome!Explanation − If we reverse 32123 then we get 32132. 32123!= 32123 ... Read More

Recursive program for prime number in C++

Sunidhi Bansal
Updated on 02-Nov-2021 08:26:06

6K+ Views

We are given an integer as input. The goal is to find whether the input number Num is a prime or non-prime using recursion.To check if a number is prime or not, start traversing from i=2 to i

Recursive Implementation of atoi() in C++

Sunidhi Bansal
Updated on 02-Nov-2021 08:20:05

2K+ Views

We are given a string containing a number. The goal is to find the equivalent number using the recursive atoi() method. int atoi(const char *str) converts the string argument str to an integer (type int).Example-:Input − Str[] = "58325"Output − The Equivalent decimal is :58325Explanation − The string contains the equivalent number 58325Input − Str[] = "00010"Output − The Equivalent decimal is :1Explanation − The string contains the equivalent number 10.Approach used in the below program is as followsIn this approach we are using the recursive function recurAtoi() which takes input string and its length and for each character convert it to decimal and multiply ... Read More

Advertisements