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
Articles by Nizamuddin Siddiqui
Page 96 of 196
How to find row minimum for an R data frame?
Data analysis is a difficult task because it has so much variation in terms of the smaller objectives of a big project. One of the smallest tasks could be finding the minimum value in each row contained in a data frame. For this purpose, we cam use apply function and pass the FUN argument as min so that we can get minimum values.Consider the below data frame −Exampleset.seed(101) x1
Read MoreHow to find critical value for one-sided and two-sided t test in R?
To find the critical value for t test in R, we need to use qt function. This function requires level of significance and the sample size and returns the tabulated or critical value of t distribution. Below examples shows the calculation of critical value for different situations such as left-side test, right-side test or two-sided test.Left side critical value with sample size 30 and 95% confidence level −Exampleqt(0.05, 30)Output[1] -1.697261Right side critical value with sample size 30 and 95% confidence level −Exampleabs(qt(0.05, 30))Output[1] 1.697261 Exampleqt(0.05, 50)Output[1] -1.675905Exampleabs(qt(0.05, 50))Output[1] 1.675905 Exampleqt(0.01, 50)Output[1] -2.403272Exampleabs(qt(0.01, 50))Output[1] 2.403272 Exampleqt(0.01, 51)Output[1] -2.401718Exampleabs(qt(0.01, 51))Output[1] 2.401718 Exampleqt(0.01, ...
Read MoreHow to create train, test and validation samples from an R data frame?
To create predictive models, it is necessary to create three subsets of a data set for the purpose of training the model, testing the model and checking the validation of the model. These subsets are usually called train, test and validation. For this purpose, we can use different type of sampling methods and the most common is random sampling. In the below example, you can see how it can be done.Consider the mtcars data set in base R −Exampledata(mtcars) str(mtcars)Output'data.frame':32 obs. of 11 variables: $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... $ ...
Read MoreHow to find the indexes of minimum values in a vector if there are ties in R?
If we have repeated values in a vector that means we have ties in the vector, therefore, the indexes of values will help us to identify the positions of a particular value in the vector. We can use which function with min function to find the positions of minimum values in a vector, if there exists more than one minimum then the output will show all the relevant positions.Examplex1
Read MoreHow to select only one column from an R data frame and return it as a data frame instead of vector?
Generally, if we extract a single column from an R data frame then it is extracted as a vector but we might want it in data frame form so that we can apply operations of a data frame on it. Therefore, we can use single square brackets for the extraction with T (TRUE) or (FALSE) values and drop = FALSE so that the output becomes a data frame.Consider the below data frame −Exampleset.seed(999) x1
Read MoreHow to calculate population variance in R?
There is no function in R to calculate the population variance but we can use the population size and sample variance to find it. We know that the divisor in population variance is the population size and if we multiply the output of var(it calculates sample variance) function with (population size – 1)/population size then the output will be population variance.Exampleset.seed(141) x1
Read MoreHow to create a point chart with empty points using ggplot2 in R?
The point chart can be created by using geom_point function and if we want to create a point chart for single vector then we should pass the vector in both the places inside aes function. Also, by default the points are complete black circles and if we want to change the points to empty points then shape argument can be used.ExampleConsider the below data frame −set.seed(171) x
Read MoreHow to generate a power sequence of two in R?
In R, for the calculation of power we can simply use power operator ^ and this will be also used in case of generating a power sequence. For example, if we want to generate a power sequence from 1 to 5 of 2 then we can use the code 2^(1:5) this will result 2 4 8 16 32.Example2^(0:2)Output[1] 1 2 4Example2^(0:10)Output[1] 1 2 4 8 16 32 64 128 256 512 1024 Example2^(0:50)Output[1] 1.000000e+00 2.000000e+00 4.000000e+00 8.000000e+00 1.600000e+01 [6] 3.200000e+01 6.400000e+01 1.280000e+02 2.560000e+02 5.120000e+02 [11] 1.024000e+03 2.048000e+03 4.096000e+03 8.192000e+03 1.638400e+04 [16] 3.276800e+04 6.553600e+04 1.310720e+05 2.621440e+05 5.242880e+05 [21] 1.048576e+06 2.097152e+06 4.194304e+06 ...
Read MoreHow to find p-value for correlation coefficient in R?
The t test is used to find the p−value for the correlation coefficient and on the basis of that we decide whether there exists a statistically significant relationship between two variables or not. In R, we can perform this test by using function cor.test. For example, if we have a vector x and y then we can find the p−value using cor.test(x,y).Example1set.seed(444) x1
Read MoreHow to convert factor levels into character in R?
To convert factor levels into character then we can use as.character function by accessing the column of the data frame that contain factor values. For example, if we have a data frame df which contains a factor column named as Gender then this column can be converted into character column as as.character(df$Gender).Exampley1
Read More