In any plot, the vertical lines are generally used to show the thresholds for something, for example, range of the variable under consideration. The package ggplot2 provides geom_vline function to create vertical lines on a plot and we have linetype argument of this function which can be used to draw dotted vertical lines.ExampleConsider the below data frame −set.seed(9) x
The rank function gives the rank of the values in a vector if the vector is sorted but in the same sequence as the original vector and the order function gives the position of the original value in the vector but in the sequence of the sorting in ascending order. The rank function is mostly used for ranking when we deal with ordinal variables, hence, we should use it whenever ranking of values is required, on the other hand, order is frequently used for ordering all numerical values.Examplesset.seed(100) x1
There are so many packages in R and each of these packages have different objectives, thus, the number of functions in these packages are large enough to solve the problems in analysis. A package might have fifteen functions and the other might have hundred, it totally depends on the necessity. We can find the functions inside a package by using lsf.str function but we need to load the package prior to knowing the functions inside.Example1library(BSDA) lsf.str("package:BSDA") CIsim : function (samples = 100, n = 30, mu = 0, sigma = 1, conf.level = 0.95, type = "Mean") Combinations : function ... Read More
If we have a long string then we might want to extract a part of string that lies between two strings. For example, if we have a string “E-learning changing the education system in the world” and we want to extract the string “the education system” brave then we must be very careful about passing the strings in string function, you get to know this in examples. The extraction is not difficult with gsub function but we have to make sure that we are using the correct syntax, otherwise, the result will become obnoxious.Examplesx1
Sometimes data is recorded as a sequence of numerical values or strings and we might to find the frequency for each of the sequences. This helps us to check the variation in the runs but we must make sure the total frequency is equal to the total number values, otherwise our calculation of frequency would be incorrect. To find the number of runs, we can use rle function in R that stands for Run Length Encoding.Examplesx1
The gridExtra package works as an alternative of par(mfrow) with ggplot2, therefore, we can create multiple plots using ggplot2 and gridExtra on a single plot window. Now, if we want to give a title to all of the plots or we can say if want to give a main title to multi-plots, the top argument will be used to make the title lie on the top of the title. Similarly, we can use bottom, left, and right on the basis of our requirement but we would also need grid package for this purpose.ExampleConsider the below data frame −set.seed(123) x1Read More
There are fifty states in United States, few of them have short names but most of the states have a lengthy name. Therefore, if we are dealing with data that has states name of United States then it will be a little complicated to access the states by using their name, hence it is preferred to use abbreviation. We can get the state name abbreviation with the help of state.abb function.Examplesstate.abb[which(state.name=="New York")] [1] "NY" state.abb[which(state.name=="California")] [1] "CA" state.abb[which(state.name=="Texas")] [1] "TX" state.abb[which(state.name=="Florida")] [1] "FL" state.abb[which(state.name=="Washington")] [1] "WA" state.abb[which(state.name=="Michigan")] [1] "MI" state.abb[which(state.name=="New Jersey")] [1] "NJ" state.abb[which(state.name=="Arizona")] [1] "AZ" state.abb[which(state.name=="Pennsylvania")] [1] "PA" state.abb[which(state.name=="Alaska")] ... Read More
There are four main restrictions on creating a vector in R. We must remember these restrictions while creating any type of vector −A vector name cannot have % sign.A vector name cannot start with a number.A vector can start with a dot but it should not have a number after it.A vector cannot start with underscore.ExamplesVectors with % sign −x1%
While we calculate correlation matrix for a data frame, all the columns must be numerical, if that is not the case then we get an error Error in cor(“data_frame_name”) : 'x' must be numeric. To solve this problem, either we can find the correlations among variables one by one or use apply function.ExampleConsider the below data frame −set.seed(99) x1
The size of a graph title mattes a lot for the visibility because it is the first thing people look at after plot area. Its size must not be very large nor very small but is should be different from the axis titles and axes labels so that there exists a clarity in the graph. This can be done by using theme function.ExampleConsider the below data frame −set.seed(1) x
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP