Find Prime Numbers Between Two Values or Up to a Value in R

Nizamuddin Siddiqui
Updated on 10-Oct-2020 12:30:22

1K+ Views

We know that the prime numbers are the numbers that are not divisible by any number except by themselves or 1 and 1 is not considered as a prime number. In R, we can find the prime numbers up to a number or between two numbers by using Prime function of numbers package. If we want to find the total number of prime numbers between 1 and 10, then we just need to pass 10 inside the Prime function, otherwise range will be required.Loading numbers package −library("numbers")Primes(10)[1] 2 3 5 7Primes(100)[1] 2 3 5 7 11 13 17 19 23 ... Read More

Difference Between Regression Line and Points in R

Nizamuddin Siddiqui
Updated on 10-Oct-2020 12:28:47

278 Views

The difference between regression line and the points on the scatterplot are actually the residuals, thus we need to calculate the residual from the model object. This can be simply done by using residuals function. For example, if we create a linear model defined as Model between x and y then the residuals will be found as residuals(Model).Consider the below data frame −Example Live Demoset.seed(999) x1

Convert Rows in an R Data Frame to List

Nizamuddin Siddiqui
Updated on 10-Oct-2020 12:18:07

2K+ Views

Sometimes each row needs to be treated differently, therefore, we might want to convert those rows into list. This will help us to perform the operations on our row elements separately. To convert the rows into list, we can use split function by defining the number of rows in the data frame.Consider the below data frame −Example Live Demoset.seed(101) x1

Find Length of Longest Common Substring in C++

Arnab Chakraborty
Updated on 10-Oct-2020 12:15:42

2K+ Views

Suppose we have two lowercase strings X and Y, we have to find the length of their longest common substring.So, if the input is like X = "helloworld", Y = "worldbook", then the output will be 5, as "world" is the longest common substring and its length is 5.To solve this, we will follow these steps −Define an array longest of size: m+1 x n+1.len := 0for initialize i := 0, when i

Combine Two Matrices to Create a Block Diagonal Matrix in R

Nizamuddin Siddiqui
Updated on 10-Oct-2020 12:10:13

878 Views

A block-diagonal matrix means that a matrix added to another matrix at the end the last element. For example, if we have a matrix with nine values and the other matrix also has nine values then the second matrix will be added to the first matrix and the elements below first matrix will be zero and the elements above the second matrix will also be zero.Example Live DemoM1

Find Length of Longest Common Subsequence in C++

Arnab Chakraborty
Updated on 10-Oct-2020 12:05:58

247 Views

Suppose we have two strings text1 and text2, we have to find the length of their longest common subsequence. As we know a subsequence of a string is a new string generated from the original string with some characters deleted without changing the relative order of the remaining characters. (So for example "abe" is a subsequence of "abcde" but "adc" is not). A common subsequence of two strings is a subsequence that is common to both strings. So If there is no common subsequence, return 0. If the input is like “abcde”, and “ace”, then the result will be 3.To ... Read More

Find Length of Longest Bitonic Subsequence in C++

Arnab Chakraborty
Updated on 10-Oct-2020 12:00:43

223 Views

Suppose we have a list of numbers. We have to find length of longest bitonic subsequence. As we knot a sequence is said to be bitonic if it's strictly increasing and then strictly decreasing. A strictly increasing sequence is bitonic. Or a strictly decreasing sequence is bitonic also.So, if the input is like nums = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15], size of sequence 16., then the output will be 7.To solve this, we will follow these steps −increasingSubSeq := new array of given array size, and fill with 1for ... Read More

Find Cube Root of Negative Values in R

Nizamuddin Siddiqui
Updated on 10-Oct-2020 11:55:32

758 Views

There is no function in R to find the cube root of negative values, hence we need to create that. The code to create the function is as shown below −CubeRoot

Create Side-by-Side Boxplot in Base R

Nizamuddin Siddiqui
Updated on 10-Oct-2020 11:54:02

434 Views

Often, we need to compare continuous variables using boxplots and thus side-by-side boxplots are required. Creating side-by-side boxplot in base R can be done with the help of creating space for graphs with the help of par(mfrow=). In this function, we can define the number of graphs and the sequence of these graphs, thus creation of side-by-side boxplot will become easy.Consider the below vectors −set.seed(100) x

Partition Color List in Python

Arnab Chakraborty
Updated on 10-Oct-2020 11:37:39

596 Views

Suppose we have a a list of color strings, these may contain "red", "green" and "blue", we have to partition the list so that the red come before green, and green come before blue.So, if the input is like colors = ["blue", "green", "blue", "red", "red"], then the output will be ['red', 'red', 'green', 'blue', 'blue']To solve this, we will follow these steps −green := 0, blue := 0, red := 0for each string in strs, doif string is same as "red", thenstrs[blue] := "blue"blue := blue + 1strs[green] := "green"green := green + 1strs[red] := "red"red := red + ... Read More

Advertisements