Create Gridlines Matching Y-Axis Values in R Plot

Nizamuddin Siddiqui
Updated on 09-Sep-2020 08:09:05

363 Views

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

Create Binary Variable Column Based on Condition in R Data Frame

Nizamuddin Siddiqui
Updated on 09-Sep-2020 08:00:43

9K+ Views

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

Maximum Difference Between Prime Numbers in Given Ranges in C++

Ayush Gupta
Updated on 09-Sep-2020 07:50:10

410 Views

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

Raise Values in an R Vector to a Power

Nizamuddin Siddiqui
Updated on 09-Sep-2020 07:49:38

1K+ Views

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

Queries for Decimal Values of Subarrays of a Binary Array in C++

Ayush Gupta
Updated on 09-Sep-2020 07:48:03

111 Views

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

Change Position of Axes Titles in R

Nizamuddin Siddiqui
Updated on 09-Sep-2020 07:46:52

271 Views

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

Frequencies of Characters in Substrings in C++

Ayush Gupta
Updated on 09-Sep-2020 07:46:24

185 Views

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

Queries for Number of Distinct Elements in a Subarray in C++

Ayush Gupta
Updated on 09-Sep-2020 07:44:10

201 Views

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

Queries for Number of Distinct Elements in a Subarray - Set 2 in C++

Ayush Gupta
Updated on 09-Sep-2020 07:43:19

448 Views

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

Find Similar Words in Vector of Strings in R

Nizamuddin Siddiqui
Updated on 09-Sep-2020 07:43:16

1K+ Views

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

Advertisements