Found 26504 Articles for Server Side Programming

Explain the concept of pointer to pointer and void pointer in C language?

Bhanu Priya
Updated on 08-Mar-2021 06:40:29

1K+ Views

Double pointer or pointer to pointer is a variable that holds the address of another pointer.Following is the declaration for a pointer to a pointer −datatype ** pointer_name;For example, int **p; p is a pointer to pointerInitialization − ‘&’ is used for initialization.For example, int a = 10; int *p; int **q; p = &a;Accessing − Indirection operator (*) is used for accessing.ExampleFollowing is the C program for the pointer to pointer − Live Demo#include main ( ){    int A = 10;    int *p;    int **q;    p = &A;    q = &p;    printf("A =%d", A); ... Read More

How to use column with colours to change the colour of points using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 07:17:27

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

How to match a column in a data frame with a column in another data frame in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 07:17:06

4K+ 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

How to find the length of columns for missing values in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 07:16:44

504 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

How to add suffix to column names in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 07:12:54

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

How to add a vector to each row of a matrix in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 07:12:36

1K+ 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

How to get the summary statistics including all basic statistical values for R data frame columns?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 07:12:00

345 Views

When we apply summary function in R, the output gives minimum, first quartile, median, mean, third quartile, and maximum but there are many other basic statistical values that help us to understand the variable such as range, sum, standard error of mean, variance, standard deviation, and coefficient of variation. Therefore, if we want to find all the values then we can use stat.desc function of pastecs package as shown in the below examples.Example1Consider the below data frame −Live Demo> x1 x2 x3 df1 df1Output            x1          x2         x3 ... Read More

How to convert a column values to column names in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 07:08:50

6K+ Views

To convert a column values to column names, we can use dcast function of reshape2 package. For example, if we have a data frame called df that contains two columns say x and y, where x is categorical and y is numerical. Now if we want to convert the categories in x as column names then it can be done as dcast(df, y~x).Example1Consider the below data frame −Live Demo> x1 x2 df1 df1Output   x1 x2 1   B  4 2   A  2 3   A  5 4   C  3 5   A  7 6   A  4 7 ... Read More

How to find the sum of variables by row in an R data frame?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 07:08:33

692 Views

To find the sum of variables by row we mean the sum of row values in the data frame. This can be easily done with the help of rowSums function. For example, if we have a data frame called df then the sum of variables by row can be found by using the command −rowSums(df)Example1Consider the below data frame −Live Demo> x1 x2 x3 df1 df1Output   x1 x2 x3 1   0  2  3 2   1  0  1 3   1  0  2 4   3  3  2 5   4  2  2 6   3  1  5 7 ... Read More

How to add proportion total at margins on a table in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 07:08:14

835 Views

The proportion total in a table helps us to understand the contribution of each row and each column in the total. Therefore, if we want to find the proportion total at margins, we can use addmargins function if we have the proportion table and if we do not have that table then firstly it needs to be created and then use the addmargins function. For example, if we have a proportion table called prop then the command will be addmargins(prop).Example1Consider the below table of proportions −Live Demo> x1 x2 x3 x4 x5 x6 x7 x8 table1 table1Output        ... Read More

Advertisements