When there is a common factor with different levels, the joining of data frames is possible but the result will present all the levels with dplyr. We can make use of left_join function to join the two data frames but the size of the first data frame must be greater than the second data frame if they are not same.ExampleConsider the below data frames −> Class df1 df1 Class 1 Statistics 2 Maths 3 Chemistry 4 Physics 5 Economics 6 Political Science 7 Geography > Subject Age df2 df2 Subject Age 1 Maths 18 2 Chemistry 21 3 Physics 22 ... Read More
Selection of top or bottom elements can be done with the help of head and tail function in R. It is required when we want to understand the data in a vector or perform some calculation for partial data.ExampleConsider the below vectors, we will use head and tail to select top and bottom elements in these vectors by using positive and negative signs. These will have a different way to select the elements.> x x [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" [20] "t" "u" "v" "w" ... Read More
Sometimes the lists are contained in another list but we want to access the nested list’s elements. Since these elements are part of a list then cannot be directly accessed, first we need to access the broader list and then the list that contains the element to reach the actual element.ExampleConsider the lists x1, x2, x3, x4, and x4 and the Total_List that contains these lists −> x1 x2 x3 x4 x5 Total_Lists Total_Lists [[1]] [[1]][[1]] [1] 1 2 3 4 5 [[1]][[2]] [1] 6 7 8 9 10 [[1]][[3]] [1] 11 12 13 14 15 [[2]] [[2]][[1]] [1] "a" ... Read More
When we deal with large data then the problem of printing the data or output of the analysis arises. Due to this problem, it becomes difficult to have a look at our complete but it can be avoided. Before importing any large data or performing any calculation that may result in big output, we can change the limit of the printing by using max.print option.Example> set.seed(1) > sample(1:1000, 555555, replace=TRUE)Output[99681] 223 62 961 304 5 262 519 357 415 167 855 523 268 486 [99695] 370 916 703 179 813 833 177 154 72 789 924 918 486 647 [99709] ... Read More
The aspect ratio of a chart can be changed in ggplot2 and this will be useful if we want a smaller image of the chart. Sometimes, we don’t have large space where the chart will be pasted therefore this functionality becomes useful. Mostly, in research reports we see charts that are of small size, hence R becomes helpful to create charts that can be pasted in the desired space. This can be done with the help of theme function.ExampleConsider the below data frame −> set.seed(100) > x df library(ggplot2)Creating the plot with aspect ratio 4/3 −> ggplot(df, aes(x))+ + geom_bar()+ ... Read More
The warning “removed n rows containing missing values” occurs when we incorrectly specify the range of the values for X-axis or Y-axis. We can this range in ggplot function using scale_x_continuous(limits=c(?, ?)) for x axis and scale_y_continuous(limits=c(?, ?)) for y axis. If the range will be larger than the actual data range then there will be no warning otherwise, we will get the warning for the number of missing values.ExampleConsider the below data frame −> set.seed(2) > x y df library(ggplot2)Creating the plot with Y-axis limits from 0 to 5−> ggplot(df, aes(x, y))+ + geom_point()+ + scale_y_continuous(limits=c(0, 5)) Warning message: ... Read More
Since visualization is an essential part of data analysis, we should make sure that the plots are created in a form that is easily readable for users. For this purpose, the facets in a bar chart helps us to understand the factor variable levels for another factor. To create such type of bar chart, we can use facet_grid function of ggplot2 package.ExampleConsider the below data frame −> set.seed(99) > y class quantity df library(ggplot2)Creating the plot with class on X-axis and y on Y-axis without any facet −> ggplot(df, aes(class, y))+ + geom_bar(stat="identity")OutputCreating the plot with class on X-axis, y ... Read More
There are some annoying messages we get while loading a package in R and they are not useful until and unless we are not loading a new package. Since these messages looks like outputs they might be confusing especially when we are analysing string data. Therefore, we must get rid of them.An example of message while loading BSDA package:>> library(BSDA)Loading required package − latticAttaching package − ‘BSDA’The following object is masked from ‘package:datasets’ −OrangeHere we have some messages while loading the package BSDA but we might not be interested in those messages if we are sure that package is installed ... Read More
Here we will see what is the balanced binary search tree. The binary search trees (BST) are binary trees, who has lesser element at left child, and greater element at right child.The average time complexity for searching elements in BST is O(log n). It is depending on the height of the binary search tree. To maintain the properties of the binary search tree, sometimes the tree becomes skewed. So the skewed tree will be look like this −This is actually a tree, but this is looking like a linked list. For this kind of trees, the searching time will be ... Read More
In this section we will see what is Brent’s Method related to open addressed hashing. This method is a heuristic. This attempts to minimize the average time for a successful search in a hash table.This method was originally applying on double hashing technique, but this can be used on any open addressing techniques like linear and quadratic probing. The age of an element x, is stored in an open addressing hash table, is the minimum value i, such that x is placed at A[xi]Brent’s Method tries to minimize the total age of all elements. If we insert an element x, ... Read More
 
 Data Structure
 Data Structure Networking
 Networking RDBMS
 RDBMS Operating System
 Operating System Java
 Java MS Excel
 MS Excel iOS
 iOS HTML
 HTML CSS
 CSS Android
 Android Python
 Python C Programming
 C Programming C++
 C++ C#
 C# MongoDB
 MongoDB MySQL
 MySQL Javascript
 Javascript PHP
 PHP 
		