
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 33676 Articles for Programming

607 Views
To create a random vector that sums to 1, we can use uniform distribution. The main thing that needs to be done cautiously is we should include 0 in the vector with randomly generating uniform distribution values. Check out the below examples to understand how it can be done.Example1Live Demo> x1 x1Output[1] 0.45490995 0.23826247 -0.07338489 -0.33361362 0.26125094 -0.45243689 [7] 0.05967125 0.43007076 0.04069027 0.37457976Example> sum(x1)Output[1] 1Example2Live Demo> x2 x2Output[1] 1.84330339 -0.11622911 -0.15001654 0.07803346 -0.17353612 0.23651847 [7] -0.21121933 -0.30938763 0.44503222 -0.64249881Example> sum(x2)Output[1] 1Example3Live Demo> x3 x3Output[1] 2.63249755 1.17230387 -0.28068787 0.58040911 -1.48530836 -0.04894802 [7] 0.66718009 0.13504265 -0.18253891 -0.49757615 1.63580429 -2.31002917 [13] 2.66256899 -2.40636756 ... Read More

218 Views
We sometimes want to highlight the main title of a plot and one of the ways to do it is changing the font of the title to a unique or using a mixed font for the title. If we want to used mixed font then we need to use the appropriate font style for the title inside as shown in the below examples.Example1> plot(rpois(10,5),main=substitute(paste(italic("Point Chart"),": Poisson Distribution")))Output:Example2> plot(rpois(10,2),main=substitute(paste(bold("Point Chart"),": Poisson Distribution")))Output:

4K+ Views
The range function in R provides the minimum and maximum values instead of the difference between the two. Hence, we can find the minimum and maximum by using range function then diff function can be used to find the actual range. For example, if we have a vector x then the range can be found by using diff(range(x)).ExampleLive Demo> x1 x1Output[1] 4 2 3 0 2 3 1 3 4 2Example> diff(range(x1))Output[1] 4 ExampleLive Demo> x2 x2Output[1] 4 5 3 10 2 4 2 4 8 7 3 1 5 6 7 3 7 3 4 5 3 7 ... Read More

219 Views
The range function in R provides the minimum and maximum values instead of the difference between the two. Hence, we can find the minimum and maximum by using range function but for a data frame we cannot use it directly. Check out the below examples to understand how it works.Example1Live Demo> set.seed(974) > x1 x2 x3 df1 df1Output x1 x2 x3 1 0 6 10 2 0 7 10 3 3 3 11 4 2 7 9 5 3 2 5 6 3 4 7 7 2 7 7 8 2 8 5 9 0 4 9 10 2 2 ... Read More

182 Views
If we find the mean of scientific numbers then the result will be also in scientific notation. We can get rid of this problem by using options(scipen=999), once we will use this code in R console all the inputs that are in scientific notation will be converted to normal numeric form, including any calculation and if we want to go back to the scientific notation then options(scipen=0) can be used.ExampleLive Demo> x1 mean(x1)Output[1] 4.436267e-22Example> options(scipen=999) > mean(x1)Output[1] 0.0000000000000000000004436267ExampleLive Demo> x2 x2Output[1] 0.000000000000000000000000000000000000001010964 [2] 0.000000000000000000000000000068291679999999998 [3] 0.000000000000000000000000006026013000000000181 [4] 0.000000000000000000000000002702241000000000107 [5] 0.000000000000000000000042258669999999998179163 [6] 0.000000000000000000000000000000091949710000000 [7] 0.000000000000000000000000000000000000107406400 [8] 0.000000000000000000000000000000091949710000000 [9] 0.000000000000000000000003463124999999999951636 [10] 0.000000000000000000004305051000000000103323794 ... Read More

795 Views
The absolute distance can be found by calculating the difference between column values. And if we want the distance to be absolute then we would be need to use abs function. For example, suppose we have a data frame df that contain columns x and y then the absolute distance can be found by using df$Absolute_Distance set.seed(274) > x1 y1 df1 df1Output x1 y1 1 6 11 2 1 4 3 4 2 4 7 12 5 4 5 6 6 10 7 6 14 8 6 8 9 2 11 10 3 8 11 3 8 12 2 6 ... Read More

472 Views
The X Window System is a windowing system for bitmap displays. In R, we can create this graphical display by simply typing x11 in the R console and the graphic interface will pop-up on the right-hand side. We can change the width and height of this display by using the arguments width and height inside x11 call. There are many other arguments of x11 that helps us to change the aesthetic property of the bitmap display. The description of those arguments is as written below:Displaythe display on which the graphics window will appear. The default is to use the value ... Read More

201 Views
The boxplot function in base R helps us to create the boxplot without any hustle but this plot is covered with a square bracket and also takes the Y-axis labels on left-hand side. We can get rid of this square bracket without making an impact on the Y-axis labels. For this purpose, we need to use frame.plot = FALSE argument inside the boxplot function.Example1> x boxplot(x,frame.plot=FALSE)Output:Example2> y boxplot(y,frame.plot=FALSE)Output:Example3> z boxplot(z,frame.plot=FALSE)Output:

871 Views
Mostly, we start with creating models by including single independent variables effect on the dependent variable and then move on to interaction. But if we are sure that there exists some interaction among variables and we are looking for the interaction effect then only interaction regression model can be created. This can be done by using colon sign between variables to signify the interaction as shown in the below examples.Example1Consider the below data frame:Live Demo> x1 x2 x3 y df1 df1Outputx1 x2 x3 y 1 1 3 10 8 2 0 3 9 11 3 1 1 6 5 4 ... Read More

3K+ Views
The splitting of data frame is mainly done to compare different parts of that data frame but this splitting is based on some condition and this condition can be row values as well. For example, if we have a data frame df where a column represents categorical data then the splitting based on the categories can be done by using subset function as shown in the below examples.Example1Consider the below data frame:Live Demo> Country Ratings df1 df1Output Country Ratings 1 India 1 2 China 2 3 Russia 5 4 Sudan 3 5 India 5 6 China ... Read More