Server Side Programming Articles

Page 1122 of 2109

How to find the significant correlation in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 661 Views

To find the significant correlation in an R data frame, we would need to find the matrix of p-values for the correlation test. This can be done by using the function rcorr of Hmisc package and read the output as matrix. For example, if we have a data frame called df then the correlation matrix with p-values can be found by using rcorr(as.matrix(df)).Example1Consider the below data frame −> x1 x2 x3 df1 df1Output            x1          x2          x3 1  -0.96730523 -1.73067540 -0.01974065 2   0.08564529 -0.05200856  0.76356487 3  -0.33694783 ...

Read More

How to change row values based on column values in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 565 Views

Changing row values based on column values means that we want to change the row values for a particular column if the column values satisfy a certain condition. For example, if we have a data frame called df that contains a column say x and we want to set all the values in x to 5 if they are greater than 5 then it can be done as df[df$x>5, ] x1 x2 df1 df1Output   x1 x2 1   3 10 2   3  3 3   1  8 4   2  4 5   1  7 6   1  4 ...

Read More

How to split a vector by equal and different number of elements in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

To split a vector by equal and different number of elements, we can use split function along with rep function. The rep function will define the repetition of the divisions for equal as well as different number of elements. For example, if a vector say x contains fifty values then splitting of x with different number of elements as 20, 10, 10, 5, 5 this can be done by using the command split(x, rep(1:5, c(20, 10, 10, 5, 5))).Example1> x1 x1Output [1]  1.30316414 -0.80488291  0.23170812 -0.07318560 -0.73388857 -0.85952329  [7] -0.88713465 -0.26618866  1.45634603  0.31282735  1.39285785  0.32501145 [13] -1.72088389 -0.20699097 -0.37173907  0.03042574 -1.88779297 ...

Read More

How to find the inverse of log10 for an R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

To find the log10 of a data frame column then log10 function will be used but to find the inverse of the log10 can be found by putting 10 raises to the power of the log10 column. For example, if we have a data frame called df that contains a column x then the log10 will be found by usinglog10(df$x)after that the inverse will be found by using 10^(df$x).Example1Consider the below data frame −> x1 x2 df1 df1Output      x1 x2 1  66210  2 2  42033  2 3  39309  2 4  80353  3 5  92864  2 6  48621  2 ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 915 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 −> x1 x2 x3 x4 x5 x6 x7 x8 table1 table1Output         [, ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 754 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 −> 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 convert a column values to column names in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 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 −> 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 add a vector to each row of a matrix in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 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 −> M1 M1Output      [, 1] [, 2]  [1, ]    3    2  [2, ]    3    3  [3, ]    4    2  [4, ]    5    1  [5, ...

Read More

How to add suffix to column names in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 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 match a column in a data frame with a column in another data frame in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 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.Example1> df1 df1Output   x1 1   2 2   2 3   1 4 ...

Read More
Showing 11211–11220 of 21,090 articles
Advertisements