- 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
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
218 Views
Sometimes date vector for months is recorded in numeric form and it becomes difficult to treat or visualize it as a date vector. For example, if a vector for months has numbers 1 that represents January, 2 that represents February and so on then it is considered as a numeric vector instead of the vector to represent the month. To transform such type of vectors into abbreviated month as Jan, Feb, etc. we can use month.abb function.ExamplesMonth1
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
4K+ Views
A vector in R can have infinite number of elements but we might want to remove some of them. To remove the last elements of a vector, we can use head function with negative sign of the number of values we do not want. For example, if we have a vector of length 200 but we don’t want last fifty elements then we can use head(vector_name,-50).Examplesx1
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
9K+ Views
Since a matrix contain only numeric values, sorting can be also done for matrices. There might be multiple reasons to sort a matrix such as we want to convert the matrix to a data frame, the data stored in matrix needs to be sorted prior to matrix calculations so that the view of the result after calculations becomes clearer, etc. To sort a matrix based on one column, we can use order function.Examplesset.seed(123) M1
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
104 Views
To generate random samples from statistical distributions, we use functions like rnorm, rbinom, rexp, rpois for the corresponding distribution based on their names. Using these functions, we can pass their parameters as an argument inside the function. But if we have the parameters saved as a list then generation of random sample is not straight forward, for this we need to use do.call function.Examplesparameters1
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
2K+ Views
Usually, a plot created in R or any of the statistical analysis software have X-axis labels on the bottom side but we might be interested in showing them at the top of the plot. It can be done for any type of two-dimensional plot whether it is a scatterplot, bar plot, etc. This is possible by using scale_x_continuous function of ggplot2 package in R.Example Live Demoset.seed(123) x
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
187 Views
An R data frame that contains two or more factor columns then there are a greater number of combinations for the number of factors, obviously, if the number of factors is large with large number of levels then the combination of levels of the factors is also large. To find total number of rows per group combination we can use transform function.ExampleConsider the below data frame − Live Demoset.seed(101) Group
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
2K+ Views
An R data frame can contain a very large number of rows and we might want to get rid of some rows if they’re not supposed to be helpful in our data analysis. Therefore, we can remove these rows prior to starting the analysis process. We can say that this removal of some rows is a part of data cleaning and obviously data cleaning helps us creating a smooth data set for analysis. In R, we can simply use head function to remove last few rows from an R data frame, also we can store them as a new data ... Read More
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
171 Views
Sorting of columns of an R data frame is not difficult but sometimes we want to sort them in opposite orders, for example, we might want to sort some columns in ascending order and some in descending order. This variation in sorting purpose makes it a little complicated. Therefore, we can use negation with sort function to sort the columns that we want to sort in descending order.ExampleConsider the below data frame − Live Demoset.seed(111) x1
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
842 Views
When we create a plot using plot function, the title of the plot appears on top of the plot while using main argument. If we use title function to create the title of the plot then we can adjust its position in many different ways such as any position between below and top border of the plot.Examplesx
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
340 Views
Rescaling a continuous means that we want to standardize it with some properties and if we are using 0 to 1 as a range that represents that property. Most of the times, the objective behind rescaling is we want to nullify the effect of measurement units of the variable under consideration. To rescale so that the range becomes 0 to 1, we can use rescale function of scales package.ExampleLoading scales package −Examplelibrary(scales) x1