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
Articles by Nizamuddin Siddiqui
Page 61 of 196
How to find the mean of very small numbers in numeric form that are represented with scientific notation in R?
If we find the mean of scientific numbers then the result will be also in scientific notation. We can get rid of this problem by using options(scipen=999), once we will use this code in R console all the inputs that are in scientific notation will be converted to normal numeric form, including any calculation and if we want to go back to the scientific notation then options(scipen=0) can be used.Example> x1 mean(x1)Output[1] 4.436267e-22Example> options(scipen=999) > mean(x1)Output[1] 0.0000000000000000000004436267Example> x2 x2Output[1] 0.000000000000000000000000000000000000001010964 [2] 0.000000000000000000000000000068291679999999998 [3] 0.000000000000000000000000006026013000000000181 [4] 0.000000000000000000000000002702241000000000107 [5] 0.000000000000000000000042258669999999998179163 [6] 0.000000000000000000000000000000091949710000000 [7] 0.000000000000000000000000000000000000107406400 [8] 0.000000000000000000000000000000091949710000000 [9] 0.000000000000000000000003463124999999999951636 [10] 0.000000000000000000004305051000000000103323794 [11] 0.000000000000000000000001542657000000000059366 ...
Read MoreHow to find the minimum and maximum of columns values in an R data frame?
The range function in R provides the minimum and maximum values instead of the difference between the two. Hence, we can find the minimum and maximum by using range function but for a data frame we cannot use it directly. Check out the below examples to understand how it works.Example1> set.seed(974) > x1 x2 x3 df1 df1Output x1 x2 x3 1 0 6 10 2 0 7 10 3 3 3 11 4 2 7 9 5 3 2 5 6 3 4 7 7 2 7 7 8 2 8 5 9 0 4 9 10 2 2 11 ...
Read MoreHow to find the range of a vector in R?
The range function in R provides the minimum and maximum values instead of the difference between the two. Hence, we can find the minimum and maximum by using range function then diff function can be used to find the actual range. For example, if we have a vector x then the range can be found by using diff(range(x)).Example> x1 x1Output[1] 4 2 3 0 2 3 1 3 4 2Example> diff(range(x1))Output[1] 4 Example> x2 x2Output[1] 4 5 3 10 2 4 2 4 8 7 3 1 5 6 7 3 7 3 4 5 3 7 2 7 ...
Read MoreHow to create a random vector in R that sums to 1?
To create a random vector that sums to 1, we can use uniform distribution. The main thing that needs to be done cautiously is we should include 0 in the vector with randomly generating uniform distribution values. Check out the below examples to understand how it can be done.Example1> x1 x1Output[1] 0.45490995 0.23826247 -0.07338489 -0.33361362 0.26125094 -0.45243689 [7] 0.05967125 0.43007076 0.04069027 0.37457976Example> sum(x1)Output[1] 1Example2> x2 x2Output[1] 1.84330339 -0.11622911 -0.15001654 0.07803346 -0.17353612 0.23651847 [7] -0.21121933 -0.30938763 0.44503222 -0.64249881Example> sum(x2)Output[1] 1Example3> x3 x3Output[1] 2.63249755 1.17230387 -0.28068787 0.58040911 -1.48530836 -0.04894802 [7] 0.66718009 0.13504265 -0.18253891 -0.49757615 1.63580429 -2.31002917 [13] 2.66256899 -2.40636756 2.03789127 0.13579276 -0.75107129 ...
Read MoreHow to create a plot using rgb colors in R?
The rgb colors are referred to red green and blue. This combination helps us to create many different colors. In R, we can use rgb function to create a plot using with different colors along with the image function. If we want to have a plot with rgb colors without any axes title or axes labels then the appropriate arguments should be used inside the image function as shown in the below example.ExampleConsider the below data frame:> set.seed(9991) > x1 x2 x3 df dfOutput x1 x2 ...
Read MoreHow to standardized a column in an R data frame?
The standardization means converting a vector or column of an R data frame in a way such that the mean of the same becomes 0 and the standard deviation becomes 1, that is it should be converted to standard normal distribution. In R, it can be easily done with the help of scale function. Check out the below example to understand how it is done.ExampleConsider the below data frame:> set.seed(3665) > x1 x2 x3 x4 x5 x6 df dfOutputx1 x2 x3 x4 x5 x6 1 1.3958185 49.39843 128.5224 3 4.183664 2.33406246 2 1.0467979 48.90103 120.5796 7 3.526731 0.02043217 3 0.9190516 ...
Read MoreHow to extract columns based on particular column values of an R data frame that match\\na pattern?
The column values of an R data frame can be easily extracted by subsetting with single square brackets but if we want to extract the column values that match a pattern then we need to use grepl function inside single square brackets, this will help us to match the pattern of the values in the data frame columns.ExampleConsider the below data frame:> set.seed(271) > x1 x2 df1 df1Output x1 x2 1 A242 B71 2 A123 B71 3 A242 B81 4 A242 B87 5 A123 B71 6 A321 B71 7 A187 ...
Read MoreHow to remove rows based on blanks in a column from a data frame in R?
Sometimes data is incorrectly entered into systems and that is the reason we must be careful while doing data cleaning before proceeding to analysis. A data collector or the sampled unit might enter blank to an answer if he or she does not find an appropriate option for the question. This also happens if the questionnaire is not properly designed or blank is filled by mistake. Also, if we have categorical variable then a control category might be filled with blank or we may want to have a blank category to use a new one at later stage. Whatever the ...
Read MoreHow to create a data frame in R with list elements?
If a list has the same length of elements (not sub-elements) as the length of each vector for which we want to create the data frame then we first need to create the data frame of vectors then we can easily add the list into the data frame. But if we have a list and other vectors then data frame cannot be created as data.frame function will read each value of the list separately.Example> df1 df1Output x y 1 6 1 2 8 1 3 6 2 4 8 1 5 5 1 6 3 1 7 6 1 8 ...
Read MoreHow to reduce a matrix in R to echelon form?
The echelon form of a matrix is the matrix that has the following characteristics:1. The first non-zero element in each row, called the leading entry, is 1.2. Each leading entry is in a column to the right of the leading entry in the previous row.3. Rows with all zero elements, if any, are below rows having a non-zero element.In R, we can use echelon function of matlib package to find the echelon form of the matrix.Example> M MOutput [, 1] [, 2] [, 3] [, 4] [, 5] [1, ] 8 11 3 10 13 [2, ] 9 ...
Read More