
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 2038 Articles for R Programming

576 Views
Subsetting is not a difficult thing in R but if we make our code short then it is a little tedious task because we will have to introduce code between codes and that creates confusion. Therefore, we must be very careful while writing a code inside another code. To create a line with subsetting the data frame using ggplot function of ggplot2 can be done by using subset function.Example Live DemoConsider the below data frame −set.seed(99) x1

409 Views
A Venn diagram helps to identify the common and uncommon elements between two or more than two sets of elements. This is also used in probability theory to visually represent the relationship between two or more events. To create a Venn diagram in R, we can make use of venn function of gplots package.ExampleConsider the below vectorsx

417 Views
Sales analysis requires to find monthly sales mean, total, range, and often standard deviation. This is mostly required by FMCG (Fast-Moving Consumer Goods) companies because they want to track their sales on daily basis as well as monthly basis. If we have daily sales data then we need to create another column for months in an R data frame to find the monthly sales and this can be done with the help of strftime and aggregate function.ExampleConsider the below data frame −date

5K+ Views
There are multiple ways to save a plot created in R. Base R provides, metafile, bitmap, and postscript options to copy and save the plots created in R but we can also save the plots created with ggplot2 as an SVG file with the help of svglite package. The ggsave function of svglite package does this job easily and we can also define the height and width of the plot inside this function.Example Live DemoInstall the svglite package −install.packages("svglite")Consider the ToothGrowth data and create a scatterplot between len and dose −head(ToothGrowth) len supp dose 1 4.2 VC ... Read More

2K+ Views
The reason we get newdata had 1 row warning is the newdata is not correctly defined. We should give the name of the explanatory variable or independent variable to the newdata so that the model can identify that we are passing the mean of the explanatory variable, otherwise it considers all the values of the explanatory hence the result of the predict function yields the predicted values for the sample size.Example Live DemoConsider the below data frame −set.seed(123) x

653 Views
When a bar plot is created then the distance or space between bars is equal but sometimes the width of the bar is large, therefore, it becomes a little difficult to understand the difference between those bars especially in cases when the data values are not very much different from each other. To overcome this visualization problem, we can create a bar plot with some space between the bars and it can be done with the help of width argument of geom_bar in ggplot2.ExampleConsider the below data frame −x

425 Views
Most of the times, the string data is in bad shape and we need to make it appropriate so that we can easily proceed with the analysis. There is also a situation in which a string column has some values where an extra space is used which was not required, therefore, it does not match with the rest of the column values. To remove these spaces, we can use lapply and gsub function.ExampleConsider the below data frame −x1

658 Views
We have to deal with date data in time series analysis, also sometimes we have a time variable in data set that is recorded to perform another type of analysis. Depending on our objective, we need to process the data and the time variable is also converted into appropriate form that we are looking for. If we want to create a sequence of months from date data then we can do it by adding a month to each upcoming month. This can be easily done by using AddMonths function of DescTools package.ExampleInstalling DescTools package −install.packages("DescTools") Loading DescTools package: library(DescTools) AddMonths(as.Date('2020/01/31'), ... Read More

508 Views
The column names in an R data frame are an important part of the data because by reading the column names any viewer is likely to understand the theoretical background behind it. If that name is not appropriate then we might want to change it. While using the aggregate function to calculate mean or any other statistical summary, it is possible to change that name with another name by defining the new name with list.ExampleConsider the below data frame −set.seed(1) x1

577 Views
In data analysis, sometimes we need to use zeros for certain calculations, either to nullify the effect of a variable or for some other purpose based on the objective of the analysis. To deal with such type of situations, we need a zero value or a vector of zeros. There are many ways to create a vector with zeros in R. The important thing is the length of the vector.Examples> x1 x1 [1] 0 0 0 0 0 0 0 0 0 0 > x2 x2 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 ... Read More