
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

8K+ Views
To find the column names and row names in an R data frame based on a condition, we can use row.names and colnames function. The condition for which we want to find the row names and column names can be defined inside these functions as shown in the below Examples.Example 1Following snippet creates a sample data frame −x1

587 Views
To find the groupwise order of values in an R data frame, we can use mutate function of dplyr package along with rank function and grouping will be done with the help of group_by function.For Example, if we have a data frame called df that contains two columns say Group and DV then we can find the groupwise order of DV values by using the command given below −df%%group_by(Group)%%mutate(Order=rank(DV))Example 1Following snippet creates a sample data frame −Group

494 Views
To create correlation matrix plot without variables labels in R, we can use tl.pos argument set to n.For Example, if we have a correlation matrix say M then we can create the correlation matrix plot without variables labels by using the below command −corrplot(M,tl.pos='n')ExampleFollowing snippet creates a sample data frame −x

4K+ Views
To extract columns with a particular string in column name of an R data frame, we can use grepl function for column names and then subset the data frame with single square brackets.For Example, if we have a data frame called df and we want to extract columns that has X in their names then we can use the command mentioned below −df[grepl("X",colnames(df))]Example 1Following snippet creates a sample data frame −Students_Score

6K+ Views
To create bar plot with gradient colors using ggplot2, we can use scale_fill_gradient function where we can set the lower and higher color values.For Example, if we have a data frame called df that contains two columns say Cat and Count then we can create the bar plot with gradient colors by using the below command −ggplot(df,aes(Cat,Count,fill=Cat))+geom_bar(stat="identity")+scale_fill_gradient(low="blue",high="red")ExampleFollowing snippet creates a sample data frame −x

742 Views
To create a ggplot2 graph with darker axes labels, darker lines, and dark titles, we can use theme_classic function of ggplot2 package with base_size argument set to a larger value.For Example, if we have a data frame called df that contains two columns say x and y then we can create the scatterplot between x and y using ggplot2 with darker axes labels, darker lines, and dark titles by using the below command −ggplot(df,aes(x,y))+geom_point()+theme_classic(base_size=22)ExampleFollowing snippet creates a sample data frame −x

494 Views
To check which column has the largest value for each row in an R matrix, we can use apply function.For Example, if we have a matrix called M then we can find column that has the largest value for each row by using the command given below −apply(M,1,which.max)Example 1Consider the matrix given below −M1

537 Views
To find the column index of least value for each row in an R matrix, we can use apply function.For Example, if we have a matrix called M then we can find column that has the least value for each row by using the command as follows −apply(M,1,which.min)Example 1Consider the matrix given below −M1

1K+ Views
To convert days in a week to number in R data frame column, we would need to convert the column into a factor by defining the weekdays as the levels and then read that column as integer.If we provide the correct sequence of weekdays during conversion then Monday will be converted to 1. Check out the below Examples to understand how it can be done.Example 1Following snippet creates a sample data frame −Week_Days