When we create a plot in R and draw gridlines then the gridlines are drawn on the basis of the values provided inside the grid function, therefore, it may or may not match with the Y-axis labels. But it can be done, we just need to set the values inside the grid function to NULL.ExampleConsider the below plot − Live Demox
Sometimes we need to create extra variable to add more information about the present data because it adds value. This is especially used while we do feature engineering. If we come to know about something that may affect our response then we prefer to use it as a variable in our data, hence we make up that with the data we have. For example, creating another variable applying conditions on other variable such as creating a binary variable for goodness if the frequency matches a certain criterion.ExampleConsider the below data frame − Live Demoset.seed(100) Group
In this problem, we are given Q queries that consist of two values L and R. Our task is to create a program to solve Queries for maximum difference between prime numbers in given ranges in C++.Problem description: Here, in each querry, we are given two values L and R. We have to find the maximum difference i.e. the difference between the largest and the smallest prime numbers within the given range.Let’s take an example to understand the problem, InputQ = 2 2 45 14 16 41 0OutputExplanationFor query 1, the smallest prime number within the given range is 2 ... Read More
Often, we need to find the power of a value or the power of all values in an R vector, especially in cases when we are dealing with polynomial models. This can be done by using ^ sign as we do in Excel. For example, if we have a vector x then the square of all values in x can be found as x^2.Example Live Demox1
In this problem, we are given a binary array bin[] and Q queries each consists of two values L and R. Our task is to create a program to solve queries for decimal values of subarrays of a binary array in C++.Problem description − Here to solve each query, we will have to find and print the decimal number which is created by the subarray starting from L to R i.e. subarray[L...R].Let’s take an example to understand the problem, Inputbin[] = {1, 1, 0, 0, 1, 0, 1, 0, 0, 0} Q = 2 2 5 0 6Output2 101ExplanationFor query ... Read More
The default position of axes titles in any software or programming language for any 2D graph is bottom for X-axis and left for Y-axis but we might to change the position of these titles to top and right respectively. This can be done by using scale_x_continuous(position="top") and scale_y_continuous(position="right") functions of ggplot2 package.ExampleConsider the below data frame − Live Demoset.seed(101) x
In this problem, we are given a string. And Q queries each has two integers l and r and character ch. our task is to create a program to solve the queries for frequencies of characters in substrings in C++.Problem description: Here for each querry, we will find the frequency of occurrence of the character ‘ch’ in the substring str[l...r].Let’s take an example to understand the problem, Inputstr = “tutorialspoint” Q = 2 0 6 t 5 13 iOutput2 2ExplanationFor query 1 − the substring is “tutoria”, the character t appears 2 times.For query 2 − the substring is “ialspoint”, ... Read More
In this problem, we are given an array arr[] of size n. And Q queries, each consisting of two elements l and r. Our task is to create a program to solve Queries for number of distinct elements in a subarray in C++.Problem description − Here for each querry, we need to find the total number of distinct integers in the subarray starting from arr[l] to arr[r].Let’s take an example to understand the problem, Inputarr[] = {5, 6, 1, 6, 5, 2, 1} Q = 2 {{1, 4}, {0, 6}}Output3 4ExplanationFor querry 1: l = 1 and r = 4, ... Read More
In this problem, we are given an array arr[] of size n and we are given a query. Each query contains two values (L, R). our task is to create a program to solve queries for number of distinct elements in a subarrayProblem description − Here, we will need to find the total number of distinct integers that are present in the subarray from the index (L-1) to (R-1).Let’s take an example to understand the problem, Inputarr[] = {4, 6, 1, 3, 1, 6, 5} query = [1, 4]Output4ExplanationFor query 1: L = 1 & R = 4, we need ... Read More
Sometimes strings in a vector of strings have spelling errors and we want to extract the similar words to avoid that spelling error because similar words are likely to represent the correct and incorrect form of a word. This can be done by using agrep with lapply function.Example 1 Live Demox1