- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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
5K+ Views
Of course, writing axes titles help viewers to understand the plot in a better way because they add more information to the plot. In general, the axes titles have simple font but we can change partial or complete title to italics to get the viewers attraction. This is needed when we want to highlight the title by making it different. In ggplot2, we can do this by using expression.ExampleConsider the below data frame −set.seed(1) x
157 Views
We use head function to take a look at some top values in an R data frame but it shows the top values for the whole data frame without considering the groups of factor column. Therefore, if we have a large number of values in a particular group then head function does not seem to be helpful alone, we must use something to extract the top values for each of the groups. This can be done through using by function with single square brackets and head function.Examplesdata(iris) str(iris) 'data.frame': 150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 ... Read More
1K+ Views
Often, we need to subset our data frame and sometimes this subsetting is based on strings. If we have a character column or a factor column then we might be having its values as a string and we can subset the whole data frame by deleting rows that contain a value or part of a value, for example, we can get rid of all rows that contain set or setosa word in Species column.ExampleConsider the below data frame −Character
2K+ Views
Sometimes we want to create a factor column of the column names and row names of a matrix so that we can use them in the analysis. It is required in situations where we want to know the effect of factor variables on the response and the factor variables were recorded as column names and row names in a matrix. To do this, we can convert the matrix into table and the table obtained is converted to data frame.ExampleConsider the below matrix −M1
2K+ Views
When we create a plot with legend using ggplot2, the legend values are covered with a box and that makes an impact on the smoothness of the plot. These boxes around the legend values can be removed so that complete the chart becomes more appealing to the viewer and it can be done with the help of theme function by setting the legend.key element to blank.ExampleConsider the below data frame −set.seed(1) x
84 Views
Labelling of points on a scatterplot helps us to identify the pair of observations. For example, if we are plotting weight and height of people then we can label it with person’s name, therefore, we will be able to understand which pair of points belong to which person. This can be done by using text function after creating the scatterplot with plot function.Examplex
813 Views
We can join vectors by columns using cbind and it does not matter whether these vectors are of same length or not. If the vectors are of same length then all the values of both the vectors are printed but if the length of these vectors are different then the values of the smaller vector gets repeated. But we might not want to repeat the values/elements of the smaller vector and it is possible by setting the length of the smaller vector to the length of larger vector, this will create NA values in the smaller at places where the ... Read More
725 Views
Mostly, we merge the data frames by columns because column names are considered prominent in data sets but it is also possible to merge two data frames by using rows. Merging by rows is likely to result in more uncleaned data as compared to the merging by columns. This can be done with the help of merge function and its by argument.ExampleConsider the below data frames −df1
369 Views
We often create subsets of data in R to perform calculations based on smaller objectives of a whole objective in data analysis projects. Sometimes this subsetting is conditional on strings instead of numeric values. We can also create a subset of data.table on the basis of substring of row values for a column by using grep function.ExampleConsider the below data.table object −x1
1K+ Views
We can create multiple plots using par(mfrow) on a single plot window in R. It might be possible that all of these plots are different or same as well. Irrespective of the type of plots, we can give a common title to all the plots. This can be a situation where we want to show, say, scatterplots, and histograms of few variables but the object of our analysis is fixed. To write a common title between plots in the plot window we can use mtext and adjust the title position by changing line argument.Exampleset.seed(100) x1