- 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)
39K+ Views
To remove a character in an R data frame column, we can use gsub() function which will replace the character with blank. For example, if we have a data frame called df that contains a character column say x which has a character ID in each value then it can be removed by using the command gsub("ID", "", as.character(df$x)).Example1Consider the below data frame −Live Demo> x1 x2 df1 df1Output x1 x2 1 Male1 8 2 Female1 4 3 Male1 9 4 Male1 2 5 Male1 7 6 Female1 5 7 Male1 3 ... Read More
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
787 Views
To create a bar plot in R, we can use barplot function but if there exist some missing values in the data then we can use ggplot2 package. For example, if we have a data frame having two vectors say x and y, x containing categorical values with NA as one of the values and y having counts/frequency for each of the categories then the bar plot will be created by using the command ggplot(df, aes(x, y))+geom_bar(stat="identity").ExampleConsider the below data frame −Live Demo> x y df dfOutput x y 1 A 24 2 B 21 3 ... Read More
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
205 Views
In data science, we often face the problem of missing values and we need to define a way to replace them with an appropriate value or we can complete remove them. If we want to replace the missing then we also need to know how many missing values are there. Therefore, if we have a data frame with grouping column then finding the number of groupwise missing values can be done with aggregate function as shown in the below examples.Example1Consider the below data frame −Live Demo> Group x df1 df1Output Group x 1 A 2 2 ... Read More
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
467 Views
The standardization of a numerical column can be easily done with the help of scale function but if we want to standardize multiple columns of a data frame if categorical columns also exist then mutate_if function of dplyr package will be used. For example, if we have a data frame df then it can be done as df%>%mutate_if(is.numeric, scale)Example1Consider the below data frame −Live Demo> x1 x2 df1 df1Output x1 x2 1 c 4 2 c 1 3 a 4 4 a 1 5 b 0 6 c 4 7 c 2 8 ... Read More
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
1K+ Views
To create a bar plot in base R with different limits for Y-axis, we can use ylim argument but generally that behaves badly, such as extending the bars below X-axis. Therefore, we need to fix those things. Check out the below example to understand how it can be done.Example> x barplot(x)OutputExample> barplot(x,ylim=c(300,600))OutputExample> barplot(x,ylim=c(300,600),xpd=FALSE)OutputExample> box(bty="l") Output
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
2K+ Views
If we have a colour column in an R data frame and we want to change the point colours in ggplot2 using that column then colour argument will be used. For example, if we have a data frame called df that contains three columns say x, y, and color then the scatterplot between x and y with the colour of points using color column can be created by using the command ggplot(df, aes(x, y))+geom_point(colour=df$color)ExampleConsider the below data frame −Live Demo> x y col df dfOutput x y col 1 ... Read More
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
3K+ Views
To match a column in a data frame with a column in another data frame, we can use match function. For example, if we have two data frames called df1 and df2 each having one similar column and the second having an extra column then the matching can be done for similar columns and a new column in the first data frame can be created based on that match and the second column the second data frame. Check out the below examples to understand how it works.Example1Live Demo> df1 df1Output x1 1 2 2 2 3 1 ... Read More
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
421 Views
The length of columns for missing values means the number of missing values in the data frame. This can be easily done with the help of colSums function where we will find the total number of NA values with is.na. For example, if we have a data frame called df that contains some missing values then the length of columns for missing values can be found by using the command colSums(is.na(df)).Example1Consider the below data frame −Live Demo> x1 x2 x3 x4 df1 df1Output x1 x2 x3 x4 1 NA NA 2 2 2 NA NA NA 2 3 1 ... Read More
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
5K+ Views
To add suffix to column names in R, we can use paste function. For example, if we have a data frame called df that contains three columns say x, y, and z and we want to add a suffix to these columns say underscore1 (_1) then it can be done by using the commandcolnames(df) x y z df1 df1Output x y z 1 6 3 2 2 9 7 5 3 5 7 6 4 5 9 6 5 2 5 9 6 4 5 4 7 2 0 7 8 2 5 8 9 4 5 8 10 6 ... Read More
![Nizamuddin Siddiqui](https://www.tutorialspoint.com/assets/profiles/218290/profile/60_42434-1594357075.jpg)
893 Views
To add a vector to reach row of a matrix, we can use addition sign (+) and create the repetition of the vector up to the number of rows in the matrix. For example, if we have a matrix called M then a vector say v can be added to each row of M by using the command −M+rep(v, each=nrow(M))Example1Consider the below matrix and the vector −Live Demo> M1 M1Output [, 1] [, 2] [1, ] 3 2 [2, ] 3 3 [3, ] 4 2 [4, ] 5 1 ... Read More