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 1367 of 3366
479 Views
In ggplot2, by default the legend title is the title of the grouping column of the data frame. If we want to change that title then scale_color_discrete function. For example, if we have a data frame called df that contains two numerical columns x and y and one grouping column say group then the scatterplot with a different legend title can be created by using the below command −ggplot(df, aes(x, y, color=group))+geom_point()+scale_color_discrete("Gender")ExampleConsider the below data frame −Live Demo> x y grp df dfOutput x y grp 1 -2.27846496 0.8121008 ... Read More
14K+ Views
Inline Function An inline function in C reduces function calls by expanding the function's code at the call site during compile time. This increases the efficiency of the function. The inline function can be substituted at the point of the function call, but this substitution is always the compiler's choice. In an inline function, the function call is replaced by the actual program code. Most Inline functions are ... Read More
4K+ Views
The preprocessor is a program that sends the source code before it passes through the compiler. It operates under preprocessor directives which begin with the symbol #.TypesThe three types of preprocessor commands are as follows −Macro substitution directives.File inclusion directives.Compiler control directives.Macro substitution directivesIt replaces every occurrence of an identifier by a predefined string.The syntax for defining a macro substitution directive is as follows −# define identifier stringFor example, #define PI 3.1415 #define f(x) x *x #undef PIExampleFollowing is the C program for the macro substitution directive −#define wait getch( ) main ( ){ ... Read More
236 Views
Type qualifiers add special attributes to existing datatypes in C programming language.There are three type qualifiers in C language and constant type qualifier is explained below −ConstThere are three types of constants, which are as follows −Literal constantsDefined constantsMemory constantsLiteral constants − These are the unnamed constants that are used to specify data.For example, a=b+7 //Here ‘7’ is literal constant.Defined constants − These constants use the preprocessor command ‘define" with #For example, #define PI 3.1415Memory constants − These constants use ‘C’ qualifier ‘const’, which indicates that the data cannot be changed.The syntax is as follows −const type identifier = valueFor ... Read More
3K+ Views
ProblemHow to convert a decimal number to a binary number by using the function in the C programming language?SolutionIn this program, we are calling a function to binary in main(). The called function to binary will perform actual conversion.The logic we are using is called function to convert decimal number to binary number is as follows −while(dno != 0){ rem = dno % 2; bno = bno + rem * f; f = f * 10; dno = dno / 2; }Finally, it returns the binary number to the main program.ExampleFollowing is the C program to ... Read More
5K+ Views
A function is a self-contained block that carries out a specific task.The advantages of function in C language are as follows −ReusabilityThe length program can be reduced.It is easy to locate and isolate a wrong function.It facilitates top-down modular programming.ExampleFollowing is the C program for functions −#include /*Function prototypes*/ myfunc(); main(){ myfunc(); } /*Function Defination*/ myfunc(){ printf("Hello "); }Here, In calculations, we generally expect a function to return a value. But, it may or may not accept the arguments.This return value has a type int, float, char or anything else.Default type of function is integer.ExampleAnother program for the ... Read More
742 Views
To create a histogram with dots instead of bars, we can use the plot function in base R. The x values will be based on the sorting of the vector values and the y values will be based on the sequence of the table for the vector values. Therefore, we would be needing sorting and table with sequence. Check out the below examples to understand how it can be done.Example1> x1 plot(sort(x1),sequence(table(x1)))OutputExample2> x2 plot(sort(x2),sequence(table(x2)))Output
4K+ Views
If we have a vector and a data frame, and the data frame has a column that contains the values similar as in the vector then we can create a subset of the data frame based on that vector. This can be done with the help of single square brackets and %in% operator. The %in% operator will help us to find the values in the data frame column that matches with the vector values. Check out the below examples to understand how it works.Example1Consider the below data frame df1 and vector v1 −Live Demo> x1 x2 df1 df1Outputx1 x2 1 ... Read More
2K+ Views
To display the average line for y variable using ggplot2, we can use geom_hline function along with the yintercept. In the yintercept, we would need to calculate the mean of the y variable and we can also change the colour of the line using color argument inside the geom_hline function.ExampleConsider the below data frame −Live Demo> x y df dfOutputx y 1 -1.07323904 0.368641641 2 0.92531148 -0.196530651 3 -0.57433739 0.710957804 4 1.17367100 0.300110517 5 0.00769624 -1.287517035 6 0.64901161 -0.476105351 7 0.70197701 -0.683592585 8 -0.80807441 -1.716264317 9 0.10827026 0.116964308 10 -1.10451308 0.660382307 11 -0.01612692 -1.182533283 12 2.20292198 -1.890223763 13 -1.03368161 -0.526983486 ... Read More
727 Views
To create a vector of random integers we can use the function sample.int and if we want to create the matrix of such integers then matrix function will be used along with it. For example, if we want to create a matrix with random integers between 1 to 100 of size 20 with 4 columns and 5 rows then it can be done by using the below command −matrix(sample.int(100,size=20),nrow=5,ncol=4)Example1Live Demo> M1 M1Output[,1] [,2] [,3] [,4] [1,] 61 8 68 81 [2,] 34 33 40 70 [3,] 76 29 51 41 [4,] 31 77 8 94 [5,] 35 57 50 29 [6,] 96 28 83 3 [7,] 11 68 71 81 [8,] 63 50 94 85 [9,] 21 53 99 94 [10,] 31 67 23 62 [11,] 56 47 68 66 [12,] 56 5 77 27 [13,] 59 95 88 64 [14,] 21 1 86 55 [15,] 8 3 72 17 [16,] 29 41 61 99 [17,] 7 62 48 56 [18,] 80 78 97 57 [19,] 26 96 34 19 [20,] 73 88 57 72Example2Live Demo> M2 M2Output[,1] [,2] [,3] [,4] [,5] [1,] 956 707 421 995 589 [2,] 525 300 595 548 109 [3,] 610 216 754 888 864 [4,] 744 240 997 246 371 [5,] 848 535 477 127 938 [6,] 836 648 241 597 608 [7,] 675 629 517 758 469 [8,] 238 433 296 249 776 [9,] 226 552 933 917 625 [10,] 111 584 643 699 573 [11,] 168 239 409 844 850 [12,] 587 387 587 899 672 [13,] 55 612 315 572 574 [14,] 765 646 925 848 584 [15,] 158 191 235 435 19 [16,] 68 631 493 604 65 [17,] 740 976 498 755 534 [18,] 241 548 921 265 343 [19,] 907 364 318 502 141 [20,] 150 739 614 444 189Example3Live Demo> M3 M3Output[,1] [,2] [1,] 2025 4158 [2,] 1372 4495 [3,] 2208 2306 [4,] 1091 476 [5,] 2635 4873 [6,] 1724 3327 [7,] 580 4051 [8,] 546 3927 [9,] 4115 2399 [10,] 1520 4577 [11,] 420 2441 [12,] 2251 1323 [13,] 2908 1415 [14,] 733 3886 [15,] 3556 844 [16,] 2181 2161 [17,] 2771 2349 [18,] 4805 2057 [19,] 2269 4561 [20,] 3110 1250Example4Live Demo> M4 M4Output[,1] [,2] [,3] [,4] [,5] [1,] 10 7 6 8 4 [2,] 2 3 9 7 6 [3,] 1 6 10 3 9 [4,] 8 1 8 7 3 [5,] 10 6 10 8 3 [6,] 2 3 9 7 10 [7,] 5 9 2 1 5 [8,] 6 4 10 1 7 [9,] 3 5 2 5 5 [10,] 2 9 8 8 7 [11,] 6 5 8 3 9 [12,] 4 1 9 6 7 [13,] 2 10 9 4 5 [14,] 10 5 2 1 2 [15,] 3 10 9 2 10 [16,] 3 6 8 8 7 [17,] 3 2 9 3 4 [18,] 9 3 3 5 4 [19,] 6 3 1 3 2 [20,] 3 7 1 7 5