
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
Found 33676 Articles for Programming

655 Views
A list contains different type of elements and each of the them can have varying elements. To subset these sub-elements we can use sapply function and use c to subset the number of corresponding sub-elements. For example, if we have a list that contains five elements and each of those elements have ten sub-elements then we can extract 1, 2, 3 etc elements from sub-elements.ExampleConsider the below list − Live Demox1

526 Views
If we have an data.table object or a data frame converted to a data.table and it has a factor column then we might want to create a frequency table that shows the number of values each factor has or the count of factor levels. This is a data summarization method which helps us to understand the variation in the occurrences of factor levels. This can be easily done with a single line of code if we have a data.table object, otherwise we first need to convert the object.ExampleConsider the below data frame − Live DemoGroup

2K+ Views
The cor function in R helps us to find the correlation matrix from a data frame or a matrix but the output of it always a matrix as intended. We might want to convert that matrix into a data frame which consists of all combination of variables with their correlation value. It can be done by reading the correlation matrix with as.table and converting that table into a data frame with as.data.frame.ExampleConsider the below data frame − Live Demox1

201 Views
If an R data frame contains all numerical columns and we want to find the difference between row values then we will lose first row of the data frame because that will not be subtracted from any row. This can be done by using head function and minus sign. It will work as subtracting the second last row from the last row, then subtracting third last row from the second last row and so on.ExampleConsider the below data frame − Live Demox1

2K+ Views
The sumproduct function in Excel multiply each value of two or more arrays with the corresponding values then add the sum of the result. For example, if we have 1, 2 in A1, A2 in Excel and 2, 2 in B1 and B2 then sumproduct will multiply 1*2 and 2*2 then take the summation of those two multiplications. In R, we have crossprod function for the same.Examples Live Demox1

1K+ Views
ExampleThere exists a possibility that one of the variables is recorded in an opposite manner and we want to create a scatterplot using that variable. Therefore, we would need to reverse that variable while plotting. Suppose that variable is an independent variable, hence it will be plotted on X-axis. Thus, to reverse the X-axis labels we can use scale_x_reverse function of ggplot2 package.Consider the below data frame −Example Live Demox

8K+ Views
Weighted mean is the average which is determined by finding the sum of the products of weights and the values then dividing this sum by the sum of total weights. If the weights are in proportion then the total sum of the weights should be 1. In base R, we have a function weighted.mean to find the weighted mean in which we just need to pass the vector of values and the vector of weights.Examples Live Demox1

629 Views
When we create a plot and put a title above it, the alignment of the title is left-adjusted by default and that lies on the edge of the plot area. But sometimes, we want to display the title on the above side of the Y-axis labels, therefore, we can use theme function and set the hjust argument accordingly.ExampleConsider the below data frame − Live Demox

513 Views
If we have summary data for a group variable then we might want to look at the errors or say differences between mean and standard deviations visually, therefore, we can create a bar plot with error bars of standard deviations. This can be done by using geom_errorbar function of ggplot2 package.ExampleConsider the below data frame − Live DemoGroup

462 Views
When we draw a scatterplot, there might be some crucial points that we would want to display, hence we create a vertical or horizontal based on our objective. These vertical or horizontal lines can be drawn by using geom_vline or geom_hline function of ggplot2 but to add some value with them we can use geom_text function.ExampleConsider the below data frame − Live Demo> x y df dfOutput x y 1 1.2474363 -0.15892165 2 1.7511870 -1.18938250 3 -1.3001612 -0.32313571 4 -1.4220049 1.52915756 5 0.4355646 0.18282983 6 0.3128323 0.16467130 7 1.5099580 1.15199751 8 -0.4907705 -1.98635182 9 -1.4249190 ... Read More