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)
To create confusion matrix for a rpart model, we first need to find the predicted values then the table of predicted values and the response variable in the original data can be created, which will be the confusion matrix for the model.For Example, if we have a vector of predicted values say P and original values in data frame df$O then the confusion matrix can be created by using the following command −table(P, df$O)Check out the below Examples to understand how it can be done.Example 1Following snippet creates a sample data frame −Dep_Var1Read More
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
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
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
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
Given two strings Str and subStr as input. The goal is to find whether text present in subStr exists in Str as substring or not. The string X is called a substring of Y if whole X is present in Y at least once. We will use a recursive approach to do this.For ExampleInput − Str = “tutorialspoint” subStr=”Point”Output − Given string does not contain substring!Explanation − The string Point is not substring of tutorialspointInput − Str = “globalization” subStr=”global”Output − Given string contains substring!Explanation − The string global is substring of globalizationApproach used in the below program is as followsIn this approach we check ... Read More
Insertion Sort is one of the sorting algorithms used to sort data by inserting elements like a deck of cards. All the elements are arranged from left to right then considering the first one as already sorted, insert rest to the sorted list on the left. Each element is compared with each element in the left list until it is inserted at its correct position.Insertion Sort Algorithmint arr[5]= { 5, 4, 2, 1, 3 };int i, j ;Traverse from index j=i+1 to jarr[i+1], swap those elements.Set temp=arr[i], arr[i]=arr[i+1] and arr[i+1]=temp.Now decrement length by 1 as the previous loop placed the ... Read More
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
To find the product of vector elements in pairs moving forward, we can use prod function along with combn function.For Example, if we have a vector called V and we want to find the product of elements of V in pairs moving forward then we can use the following command −combn(V,2,prod)Example 1Following snippet creates a sample data frame −x1
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP