Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 1209 of 2109
How to remove continuously repeated duplicates in an R data frame column?
Often values are repeated that generate duplication in the data and we might want to get rid of those values if they are not likely to create bias in the output of the analysis. For example, if we have a column that defines a process and we take the output of the process five times but it takes the same output all the time then we might want to use only one output.Example1ID
Read MoreHow to create normal quantile-quantile plot for a logarithmic model in R?
How to create normal quantile-quantile plot for a logarithmic model in R?A logarithmic model is the type of model in which we take the log of the dependent variable and then create the linear model in R. If we want to create the normal quantile-quantile plot for a logarithmic model then plot function can be used with the model object name and which = 2 argument must be introduced to get the desired plot.Example1> x1 x1Output[1] 4.735737 3.631521 5.522580 5.538314 5.580952 4.341072 4.736899 2.455681 [9] 4.042295 5.534034 4.717607 6.146558 4.466849 5.444437 5.390151 4.491595 [17] 4.227620 4.223362 5.452378 5.690660 5.321716 5.269895 ...
Read MoreHow to set the diagonal elements of a matrix to 1 in R?
First thing we need to understand is diagonal elements are useful only if we have a square matrix, otherwise it would not make sense to set diagonal elements, this is known to almost all mathematicians but some freshman might get confused because we can create diagonal in a non-square matrix which should not be called a diagonal. In R, we can set the diagonal elements of a matrix to 1 by using diag function.Example1> M1 M1Output [, 1] [, 2] [, 3] [, 4] [, 5] [1, ] 1 6 11 16 21 [2, ...
Read MoreHow to fix the coefficient of an independent variable in R?
While doing the analysis we might know the variation in an independent variable or we might want to understand how other independent variables behave if we fix a certain variable. Therefore, we can fix the coefficient of an independent variable while creating the model and this can be done by using offset function with the coefficient of the variable for which we want to fix the value of the coefficient.ExampleConsider the below data frame:> set.seed(854) > x1 x2 y1 df1 df1Output x1 x2 y1 ...
Read MoreHow to create relative frequency table using dplyr in R?
The relative frequency is the proportion of something out of total. For example, if we have 5 bananas, 6 guava, 10 pomegranates then the relative frequency of banana would be 5 divided by the total sum of 5, 6, and 10 that is 21 hence it can be also called proportional frequency.Example1y%mutate(freq=n/sum(n)) `summarise()` ungrouping output (override with `.groups` argument) # A tibble: 2 x 3Outputy n freq 1 Female 11 0.55 2 Male 9 0.45 Warning message: `...` is not empty. We detected these problematic arguments: * `needs_dots` These dots only exist to allow future extensions and should be empty. Did you misspecify an argument?
Read MoreHow to convert diagonal elements of a matrix in R into missing values?
First thing we need to understand is diagonal elements are useful only if we have a square matrix, otherwise it would not make sense to set diagonal elements, this is known to almost all mathematicians but some freshman might get confused because we can create diagonal in a non-square matrix which should not be called a diagonal. In R, we can set the diagonal elements of a matrix to missing values/NA by using diag function.Example1> M1 M1Output [, 1] [, 2] [, 3] [, 4] [1, ] 1 5 9 13 [2, ] 2 6 ...
Read MoreHow to calculate the sensitivity and specificity from a confusion matrix in R?
If we have a confusion matrix then the sensitivity and specificity can be calculated using confusionMatrix function of caret package. For example, if we have a contingency table named as table then we can use the code confusionMatrix(table). This will return sensitivity and specificity as well as many other metrics.Example1> x1 y1 table1 table1Outputy1 x1 a b c d a 0 0 1 0 b 0 1 2 1 c 2 2 0 2 d 3 2 1 3Loading caret package:> library(caret)Finding sensitivity and specificity of table1:> confusionMatrix(table1)Confusion Matrix and StatisticsOutputy1 x1 a b c d ...
Read MoreHow to replace "and" in a string with "&" in R?
We know that the word “and” can be written as “&”. If we have vectors that contain string values separated with word “and” then we can replace it with “&”. To do this, we can use stri_replace_last function of stringi package. For example, if we have a string vector that contain only one element defined as x
Read MoreHow to find the row-wise index of non-NA values in a matrix in R?
A matrix can also contain missing values and those missing values can be placed in a matrix by randomization as well, hence we cannot be sure about the positions of those values that are referred to as NA and the non-missing values. If we want to find the positions of the non-missing values in a matrix then apply function can be used where we can use which function to exclude NA values. Check out the below examples to understand how it works.Example1M1
Read MoreHow to convert a list into an array in R?
To convert a list into an array then firstly we need to unlist the list elements and then use the array function. For example, if we have a list defined as List then it can be converted into an array using the command array(unlist(List)). Suppose the list contain the elements as shown below −1 2 3 4 5 1 2 3 4 5 1 2 3 4 5If we convert this list into an array then the output will be 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5.Example1List1
Read More