
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

2K+ Views
Mostly, the bar plot is created with frequency or count on the Y-axis in any way, whether it is manual or by using any software or programming language but sometimes we want to use percentages. It can be done by using scales package in R, that gives us the option labels=percent_format() to change the labels to percentage.ExampleConsider the below data frame − Live Demo> x df dfOutput x 1 2 2 3 3 3 4 1 5 2 6 4 7 4 8 4 9 2 10 3 11 3 12 4 13 3 14 4 15 4 16 1 17 3 ... Read More

10K+ Views
To replace a value in an R vector, we can use replace function. It is better to save the replacement with a new object, even if you name that new object same as the original, otherwise the replacements will not work with further analysis. As you can see in the object x5(in examples), when we replaced 5 with 3, the previous replacement of -1 with 0 returned as in original vector. Therefore, we should save it in a new object.Examples Live Demo> x1 x1Output[1] 1 2 3 4 5 6 7 8 9 10 > replace(x1, x1==5, 10)Output[1] 1 2 3 ... Read More

3K+ Views
While doing the data analysis, often we have to deal with factor data and we might want to find the frequency or count of a level of factor and the other variable combination. This helps us to make comparison within and between factor levels. Therefore, we can add a new column as count to find the required frequency and it can be done by using group_by and mutate function of dplyr package.ExampleConsider the below data frame − Live Demo> Group Rating df head(df, 20)Output Group Rating 1 A 1 2 B 6 3 C 2 ... Read More

2K+ Views
Cumulative sums are often used to display the running totals of values and these sums also help us to identify the overall total. In this way, we can analyze the variation in the running totals over time. To create the cumulative sum chart with count on Y-axis we can use stat_bin function of ggplot2 package.ExampleConsider the below data frame − Live Demo> x df head(df, 20)Output x 1 1.755900133 2 1.185746239 3 0.821489888 4 1.358420721 5 2.719636441 6 2.885153151 7 1.131452570 8 0.302981998 9 0.433865254 10 2.373338327 11 0.428436149 12 1.835789725 13 2.600838211 14 2.108302471 15 1.164818373 16 1.547473189 ... Read More

3K+ Views
Often the data frames and matrices in R, we get have missing values and if we want to find the correlation matrix for those data frames and matrices, we stuck. It happens with almost everyone in Data Analysis but we can solve that problem by using na.omit while using the cor function to calculate the correlation matrix. Check out the examples below for that.ExampleConsider the below data frame − Live Demo> x1 x2 x3 x4 df head(df, 20)Output x1 x2 x3 x4 1 2 2.6347839 4 2.577690 2 3 0.3082031 1 6.250998 3 1 0.3082031 3 7.786711 4 ... Read More

3K+ Views
When we create a boxplot using ggplot2, the default width of the lines in the boxplot is very thin and we might want to increase that width to make the visibility of the edges of the boxplot clearer. This will help viewers to understand the edges of the boxplot in just a single shot. We can do this by using lwd argument of geom_boxplot function of ggplto2 package.ExampleConsider the below data frame − Live Demo> ID Count df head(df, 20)Output ID Count 1 S1 20 2 S2 14 3 S3 17 4 S4 30 5 S1 17 6 S2 23 7 S3 ... Read More

292 Views
When we have repeated elements in an R vector and the vector size is large then we might want to know the distinct values in that vector. This will help us to understand the unique values we have in our vector, so that we can create the appropriate chart and perform the appropriate analysis using that vector. This can be done by using length function with unique.Examples Live Demo> x1 x1Output[1] 2 5 5 3 2 4 3 3 1 4 5 4 5 3 3 1 1 2 5 1 3 2 4 1 3 1 5 4 2 5 ... Read More

2K+ Views
To find the row and column indices of values in a matrix, we cannot simply use which function because it returns the index based on sequence of the numbers in the matrix. For example, if we have a matrix M as below −1 2 3 4 1 6 7 8 1Now if we try to find the index using which(M==1) then it will return 1 5 9Because 1 is placed at 1, 5 and 9.Hence, we need to use arr.ind = TRUE so that the matrix can be read as an array by which function.ExampleConsider the below matrix − Live Demo> ... Read More
How to extract values from an R data frame column that do not start and end with certain characters?

131 Views
Sometimes we just want to extract the values of a data column based on initial and ending values of a column that has strings or sometimes the values of a column that has strings are recorded with some extra characters and we want to extract those values. For this purpose, we can use negation of grepl with single square brackets.ExampleConsider the below data frame −> x2 df2 head(df2, 20)Outputx2 1 Alabama 2 Alaska 3 American Samoa 4 Arizona 5 Arkansas 6 California 7 Colorado 8 Connecticut 9 Delaware 10 District of Columbia 11 Florida 12 Georgia 13 Guam 14 Hawaii ... Read More

1K+ Views
A footnote is generally used to give references to a document, text or image and it is called citation. It helps the reader or viewer to check out the original source using the new text or image is generated. If we want to give citation to a plot in R using ggplot2 package then we can add labs that has caption option to add the footnotes.ExampleConsider the below data frame − Live Demo> set.seed(1) > x y df dfOutput x y 1 0.8735462 4.0117812 2 1.6836433 2.8898432 3 0.6643714 1.8787594 4 3.0952808 0.2853001 5 1.8295078 3.6249309 ... Read More