Found 26504 Articles for Server Side Programming

How to display R-squared value on scatterplot with regression model line in R?

Nizamuddin Siddiqui
Updated on 08-Oct-2020 14:20:27

8K+ Views

The R-squared value is the coefficient of determination, it gives us the percentage or proportion of variation in dependent variable explained by the independent variable. To display this value on the scatterplot with regression model line without taking help from any package, we can use plot function with abline and legend functions.Consider the below data frame −Example Live Demoset.seed(1234) x

How to find the absolute pairwise difference among values of a vector in R?

Nizamuddin Siddiqui
Updated on 08-Oct-2020 14:15:54

489 Views

If a vector contains five values then there will be ten pairwise differences. For example, suppose we have five numbers starting from 1, then the pairwise combinations for these values will be (1,2), (1,3), (1,4), (1,5), (2,3), (2,4), (2,5), (3,4), (3,5), (4,5). Now to find the absolute pairwise differences, we would be need to find the differences between each of these combinations and take the absolute value of the answer hence the result will be 1, 2, 3, 4, 1, 2, 3, 1, 2, 1.Example Live Demox1

Program to find total mutation group of genes in C++

Arnab Chakraborty
Updated on 08-Oct-2020 14:17:07

357 Views

Suppose we have a list of strings called genes where each element has the same length and each element contains characters "A", "C", "G" and/or "T". Now there are some rules −When two strings s1 and s2 are the same string except for one character, then s1 and s2 are in the same mutation group.When two strings s1 and s2 are in a group and s2 and s3 are in a group, then s1 and s3 are in the same group.We have to find the total number of mutation groups we can generate.So, if the input is like genes = ... Read More

How to create a sequence of dates by using starting date in R?

Nizamuddin Siddiqui
Updated on 08-Oct-2020 14:11:47

1K+ Views

The best way to create a sequence of anything is creating it with the help of seq function and this also applies to sequences of dates. But in case of dates, we need to read the dates in date format so that R can understand the input type and create the appropriate vector. If we do not use the date format for the date value then it won’t make sense to R and it will result in error.Examples Live Demox1

Program to implement the fractional knapsack problem in Python

Arnab Chakraborty
Updated on 08-Oct-2020 14:10:45

2K+ Views

Suppose we have two lists, weights and values of same length and another value capacity. The weights[i] and values[i] represent the weight and value of ith element. So if we can take at most capacity weights, and that we can take a fraction of an item's weight with proportionate value, we have to find the maximum amount of value we can get (rounded down to the nearest integer)So, if the input is like weights = [6, 7, 3] values = [110, 120, 2] capacity = 10, then the output will be 178.To solve this, we will follow these steps −res ... Read More

How to create a contingency table with sum on the margins from an R data frame?

Nizamuddin Siddiqui
Updated on 08-Oct-2020 14:09:35

2K+ Views

The sum of rows and columns on the margins in a contingency table are always useful because they are used for different type of calculations such as odds ratio, probability etc. If an R data frame has factor columns then we can create a contingency table for that data frame and it can be done by using addmargins function.ExampleConsider the below data frame − Live Demox1

Program to check given graph is a set of trees or not in Python

Arnab Chakraborty
Updated on 08-Oct-2020 10:42:45

277 Views

Suppose we have a graph, represented as a list of edges. We have to check whether the graph is a collection of trees (forest) or not.So, if the input is likethen the output will be TrueTo solve this, we will follow these steps −Define a function dfs() . This will take node, previf node in seen, thenreturn Falseinsert node into seenfor each adjacent node n in e[node], doif n is not same as prev, thenif dfs(n, node) is false, thenreturn Falsereturn TrueFrom the main method, do the following −e := an empty mapfor each start node u and end node ... Read More

Program to find correct order of visited cities in C++

Arnab Chakraborty
Updated on 08-Oct-2020 10:32:22

216 Views

Suppose we have a list of airline tickets represented by pairs of departure and arrival airports like [from, to], we have to reconstruct the itinerary in correct order. All of the tickets belong to a man who departs from KLK. So, the itinerary must begin with JFK.So if the input is like [["MUC", "LHR"], ["KLK ", "MUC"], ["SFO", "SJC"], ["LHR", "SFO"]], then the output will be ["KLK ", "MUC", "LHR", "SFO", "SJC"].To solve this, we will follow these steps −Define array ret and a map called graph.Define a method called visit. This will take airport name as inputwhile size of ... Read More

Program to find first positive missing integer in range in Python

Arnab Chakraborty
Updated on 08-Oct-2020 10:28:27

347 Views

Suppose we have a list of sorted list of distinct integers of size n, we have to find the first positive number in range [1 to n+1] that is not present in the array.So, if the input is like nums = [0, 5, 1], then the output will be 2, as 2 is the first missing number in range 1 to 5.To solve this, we will follow these steps −target := 1for each i in arr, doif i is same as target, thentarget := target + 1return targetLet us see the following implementation to get better understanding −Example Live Democlass Solution: ... Read More

Program to find lowest possible integer that is missing in the array in Python

Arnab Chakraborty
Updated on 08-Oct-2020 10:25:57

193 Views

Suppose we have a list of numbers called nums, we have to find the first missing positive number. In other words, the lowest positive number that does not present in the array. The array can contain duplicates and negative numbers as well.So, if the input is like nums = [0, 3, 1], then the output will be 2To solve this, we will follow these steps −nums := a set with all positive numbers present in numsif nums is null, thenreturn 1for i in range 1 to size of nums + 2, doif i is not present in nums, thenreturn iLet ... Read More

Advertisements