Compute Zeroes: Solutions of a Mathematical Equation in JavaScript

AmitDiwan
Updated on 17-Oct-2020 09:01:46

115 Views

We are required to write a JavaScript function that takes in three numbers (representing the coefficient of quadratic term, coefficient of linear term and the constant respectively in a quadratic quadratic).And we are required to find the roots, (if they are real roots) otherwise we have to return false.ExampleThe code for this will be −const coeff = [1, 12, 3]; const findRoots = co => {    const [a, b, c] = co;    const discriminant = (b * b) - 4 * a * c;    // non real roots    if(discriminant < 0){       return false; ... Read More

Sort List with Single Sub-Elements in Decreasing Order in R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 09:00:48

137 Views

Just like a list can have multiple elements, the elements of the list can have multiple sub-elements and the size of those elements may vary as well hence a list with single sub-elements is also possible. If we have such type of list then we can sort that list in decreasing order by using order function but we also need to unlist those elements.ExampleConsider the below list − Live Demox1

Keeping Only Redundant Words in a String in JavaScript

AmitDiwan
Updated on 17-Oct-2020 08:59:48

419 Views

We are required to write a JavaScript function that takes in a string and returns a new string with only the words that appeared for more than once in the original string.For example:If the input string is −const str = 'this is a is this string that contains that some repeating words';OutputThen the output should be −const output = 'this is that';Let’s write the code for this function −ExampleThe code for this will be −const str = 'this is a is this string that contains that some repeating words'; const keepDuplicateWords = str => {    const strArr = str.split(" ... Read More

Create Histogram of All Columns in an R Data Frame

Nizamuddin Siddiqui
Updated on 17-Oct-2020 08:57:46

14K+ Views

To create histogram of all columns in an R data frame, we can use hist.data.frame function of Hmisc package. For example, if we have a data frame df that contains five columns then the histogram for all the columns can be created by using a single line code as hist.data.frame(df).ExampleConsider the below data frame − Live Demoset.seed(9) x1

Find Frequency of NA Values per Row in R Data Frame

Nizamuddin Siddiqui
Updated on 17-Oct-2020 08:52:31

486 Views

Since column represent variables, we often find missing values in the columns of a data frame but we may want to find missing values(NA) for cases as well so that we can replace them based on case characteristic instead of the distribution of the variable. In R, we can use rowSums with apply function.ExampleConsider the below data frame − Live Demoset.seed(8) x1

Find Maximum Value for Each Column of a Matrix in R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 08:45:09

5K+ Views

To find the maximum value for each column of a matrix, we need to use apply function. For example, if we have a matrix M that contains 2 rows and 2 columns with values 1, 2 in the first row and 3, 4 in the second row then the maximum for each of the columns in that matrix can be found by using the syntax; apply(M,2,max), hence the result will be 3, 4.Example Live DemoM1−-matrix(1:36,ncol=6) M1Output   [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1    7    13   19   25   31 [2,] 2    8    14   20   26   32 [3,] 3    9    15   21   27   33 [4,] 4    10   16   22   28   34 [5,] 5    11   17   23   29   35 [6,] 6    12   18   24   30   36Exampleapply(M1,2,max)Output[1] 6 12 18 24 30 36Example Live DemoM2

Find the Median of All Columns in an R Data Frame

Nizamuddin Siddiqui
Updated on 17-Oct-2020 08:35:42

9K+ Views

The median is the value in a vector that divide the data into two equal parts. To find the median of all columns, we can use apply function. For example, if we have a data frame df that contains numerical columns then the median for all the columns can be calculated as apply(df,2,median).ExampleConsider the below data frame − Live Demoset.seed(7) x1

Remove Column from Data Frame with Same Value in R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 08:30:45

396 Views

If we have only one value in all of the rows of an R data frame then we might want to remove the whole column because the effect of that column will not make any sense in the data analysis objectives. Thus, instead of removing the column we can extract the columns that contains different values.Example Live Demoset.seed(1001) x1

Find Confidence Interval for Predictive Value Using Regression Model in R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 08:20:36

582 Views

The confidence interval for the predictive value using regression model can be found with the help of predict function, we just need to use interval argument for confidence and the appropriate level for that. For example, if we have a model M and the data frame for the values of independent variable is named as newdata then we can use the following syntax for the confidence interval −predict(M,newdata,se.fit=TRUE,interval="confidence",level=0.95)ExampleConsider the below data frame − Live Demoset.seed(1234) x1

Remove Outliers from Multiple Boxplots in R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 08:16:08

552 Views

A data frame can have multiple numerical columns and we can create boxplot for each of the columns just by using boxplot function with data frame name but if we want to exclude outliers then outline argument can be used. For example, if we have a data frame df with multiple numerical columns that contain outlying values then the boxplot without outliers can be created as boxplot(df,outline=FALSE).ExampleConsider the below data frame: Live Demoset.seed(151) x1

Advertisements