Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1375 of 2650
372 Views
If a data frame contains missing value then visualising it in base R is not easily possible but we can make use of visdat package for this purpose. The vis_dat function of visdat package helps to visualize any data frame even if it contains missing values. For example, if a data frame df contains missing value then it can be visualized as vis_dat(df).Example1Consider the below data frame −Live Demo> x1 x2 x3 df1 df1Output x1 x2 x3 1 1 23 10 2 1 23 NA 3 NA NA 10 4 NA NA 10 5 1 24 NA 6 2 22 ... Read More
228 Views
To create a line for equal values of x and y in scatterplot, we can make use of segments function in base R but this can be done after creating the plot with the help of plot function. The segments function has four arguments, x0, y0, x1, and y1, we need to put the same value in x0 and y0 and the same value in x1 and y1 to draw the appropriate line as shown in the below examples.Example1Live Demo> x xOutput[1] -1.14191974 1.11554154 -0.01255755 1.18841175 1.11300329 -0.69925814 [7] -0.88000117 0.67830803 -0.91237446 -1.14223973ExampleLive Demo> y yOutput[1] -1.69229826 -0.70352587 0.38544874 0.14022473 ... Read More
790 Views
To plot the confidence interval of the regression model, we can use geom_ribbon function of ggplot2 package but by default it will have dark grey color. It can become transparent with the help of alpha argument inside the same function, the alpha argument can be adjusted as per our requirement but the most recommended value by me is 0.2.ExampleConsider the below data frame −Live Demo> x y df dfOutput x y 1 22.67102 29.37057 2 21.59415 29.54027 3 20.56817 28.27672 4 24.97228 31.38193 5 21.41651 31.86811 6 ... Read More
871 Views
In Data Analysis, we often required to extract a single value, a single row, or a single column for a specific analysis. For example, if data frame contains column defined as height and weight then we might want to use only height then it can be extracted, this could be a part of a list as well, therefore, extraction from list will be required. If we have a list of data frames then extraction of a column from one of the data frames in the list can be done by using double square brackets for accessing the data frame and ... Read More
1K+ Views
To convert a matrix into a color matrix, we can make use of image function. There are multiple ways for assigning the colors but the easiest one might be by defining the minimum and maximum value in the matrix. Also, we can do this by using the shades of a single color as shown in the example 3.Example1Live Demo> M1 M1Output [, 1] [, 2] [, 3] [, 4] [, 5] [1, ] 6 3 5 4 3 [2, ] 9 4 5 2 5 [3, ] 3 2 ... Read More
161 Views
To create a plot with tick marks but without axes lines, we first need to create the plot without axes and then add the tick marks. This can be done with the help of plot function and axis function in base R. The axis function will help us to decide where do we need the tick marks and the ticks.Example1> plot(1:10,axes=FALSE) > axis(1,c(1:10),col=NA,col.ticks=1)OutputExample2Live Demo> x xOutput[1] 5 2 1 2 1Example> plot(x,axes=FALSE) > axis(1,c(1:5),col=NA,col.ticks=1)Output
473 Views
If we have a list of data frames and the size of those data frames is same then we might want to combine the lists so that the data frames can be combined. This can be done by using mapply function along with cbind. For example, if we have two lists of data frames defined as List1 and List2 then we can combine them using the command −mapply(cbind, List1, List2, SIMPLIFY=FALSE).ExampleConsider the below data frame −Live Demo> x1 x2 df1 df1Output x1 x2 1 0.2378371 0.51433808 2 0.0638975 -1.66077353 3 0.3987209 0.68480587 ... Read More
4K+ Views
Generally, the space between two legend entries is not large enough and it becomes difficult to read the legend names if the names are long. In this case, we need to increase the margin between the legend entries/names but this would be required when the legends are horizontally aligned as vertical legends can be read as it is. For this purpose, we can use legend.text argument inside theme function of ggplot2 package.ExampleConsider the below data frame −Live Demo> x y df dfOutput x y 1 Male 501 2 Female 520Loading ggplot2 ... Read More
578 Views
The data collected for the first time is utilised as it is but when we need to go for secondary data to conduct the same or similar study again, we can use new data as well as the primary data. In this type of situations, we might want to randomly organize data rows that includes new and old data. Also, there is a possibility of missing data row which is found at later stage in the study then it can be also added. Hence, a row might be required to added in the existing data frame. This can be done ... Read More
306 Views
Suppose we have the preorder traversal of a binary search tree (BST). We have to check whether each internal node has only one child or not.So, if the input is like preorder = [22, 12, 13, 15, 14], then the output will be True as BST is like −To solve this, we can follow one efficient approach. As all decedents of a node is either smaller or larger, then we can we can follow these steps −Get the next preorder successor of the nodeGet the last preorder successor of the nodeNow when both the successors are less than or greater ... Read More