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
Programming Articles - Page 930 of 3363
2K+ Views
Suppose we have a vector say V that contains five elements and a matrix say M that has five columns. Now again, suppose that we want to divide each column in M by corresponding value in vector V, which means first column in M will be divided by first value in the V and so on then we can use the sweep function as shown below −sweep(M,2,V,FUN="/")Example 1Consider the below matrix and vector −M1
77K+ Views
To remove all rows having NA, we can use na.omit() function. For Example, if we have a data frame called df that contains some NA values then we can remove all rows that contains at least one NA by using the command na.omit(df).That means if we have more than one column in the data frame then rows that contains even one NA will be removed. Check out the below Examples to understand how it works.Example 1Consider the below data frame −x1
284 Views
We can create a circle in R by using draw.circle function of plotrix package and if we want to have vertical lines inside the circle then density and angle arguments will be used. The density argument will create the lines and angle argument will set the direction of those lines.For vertical lines the angle will be 270 and the number of lines depends on the value of density argument.Check out the below Examples to understand how different values of density create lines inside the circle.ExampleTo create a circle in R, use the code given below −plot(1:10, type="n")OutputIf you execute the ... Read More
313 Views
To create a 90-degree arc in R, we can use draw.arc function of plotrix package where we can use deg2 argument. Since, a 90-degree can be drawn in four ways; we need to pass the degree depending on the position of the arc we want to display.Check out an Example explained below.ExampleTo create a 90-degree arc in R, add the following code −plot(1:10, type="n")OutputIf you execute the above given snippet, it generates the following Output −To create a 90-degree arc in R, add the following code to the above snippet −plot(1:10, type="n") draw.arc(5, 5, 2, deg2=90, col="blue")OutputIf you execute all ... Read More
529 Views
We can create a circle in R by using draw.circle function of plotrix package and default border color of the circle is black. If we want to change the border color of a circle then we can use border argument and pass the desired colors.For Example, if we want to create a blue colored circle then, we can use the below mentioned command −draw.circle(5, 5, 2, border="blue")Check out the below Example to understand how it works.ExampleTo create a colored circle add the following code to the above snippet −plot(1:10, type="n")OutputIf you execute the above given snippet, it generates the following ... Read More
870 Views
To fill bars in a bar plot using ggplot2 in R with colors based on frequency, we can use fill argument with count.For Example, if we have a data frame called df that contains a single column X that contains repeated values and we want to create bar plot of values in X based on their frequencies then we can use the below command −ggplot(df)+geom_bar(aes(X,fill=..count..))ExampleConsider the data frame given below −x
436 Views
To create a time series plot in R without time vector, we can use ts.plot function.For Example, if we have a vector called X then we can create the time series plot of X by using the command ts.plot(X), the Output of this command will have a time axis in place of X-axis. Check out the below Examples to understand how it works.Example 1Consider the following vector −x
3K+ Views
To create a plot of matrix elements with the help of corrplot function, we would need to set is.corr argument to FALSE so that the matrix values will be plotted in the diagram, otherwise, the corrplot function requires correlation matrix instead of a matrix hence there will be an error as shown in the Example below.ExampleConsider the matrix given below −M
786 Views
To draw concentric circles, we can use draw.circle function of plotrix package but firstly, we would need to create a blank graph with plot function as shown below.For Example, we can create three concentric circles at position X=5 and Y=5 having radius of 1, 2, and 3 by using the below command −draw.circle(5, 5, c(3, 2, 1), col=c("blue", "red", "green"))ExampleTo create three concentric circles at position X=5 and Y=5 having radius of 1, 2, and 3 add the following code to the above snippet −plot(1:10, type="n")OutputIf you execute all the above given snippets as a single program, it generates the ... Read More
547 Views
To create vertical line in xyplot, we can use abline function.For Example, if we have a data frame called df that contains two columns say X and Y and we want to create a scatterplot between X and Y using xyplot with a vertical line at X = 2 then we can use the below command −xyplot(y~x,df,abline=c(v=2))ExampleConsider the data frame given below −x