R Programming Articles

Page 15 of 174

How to assign a value to a base R plot?

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

To assign a value to a base R plot, we can follow the below steps −First of all, create a vector and its histogram then record it with recordPlot function in an object.Then, use dev.off function to remove the plot.After that, read the plot with object name.Create the vector and histogram then save it in an objectLet’s create a vector of normal distribution and create its histogram then save it in an object called Histogram using recordPlot as shown below −x

Read More

How to scale the R data frame by excluding a particular column?

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

To scale the R data frame by excluding a particular column, we can follow the below steps −First of all, create a data frame.Then, subset the data frame with single square brackets and scale function.Create the data frameLet’s create a data frame as shown below −Group

Read More

How to convert a correlation matrix into a logical matrix based on correlation coefficient in R?

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

To convert a correlation matrix into a logical matrix based on correlation coefficient in R, we can follow the below steps −First of all, create a matrix.Then, find the correlation matrix.After that, convert the correlation matrix into logical matrix based on coefficient value using greater than or less than sign.Example 1Let’s create a matrix as shown below −M1

Read More

How to find the sum of numbers stored in character vector separated with a special character in R?

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

To find the sum of numbers stored in character vector separated with a special character in R, we can follow the below steps −First of all, create a vector having numbers stored in character vector separated with a special character.Then, use sapply and strsplit function to find the sum of numbers.Example1Create a vector with numbers stored in character vector separated with hyphen −> x1 x1On executing, the above script generates the below output(this output will vary on your system due to randomization) − [1] "11-2-15-19-10"   "11-2-15-19-10"    "13-12-75-29-18"  "15-25-52-91-10"  [5] "15-25-52-91-10"  "17-27-55-91-100"  "13-12-75-29-18"  "15-25-52-91-10"  [9] "13-12-75-29-18"  "10-4-5-19-10"     "17-27-55-91-100" ...

Read More

How to subtract column values from column means in R data frame?

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

To subtract column values from column means in R data frame, we can follow the below steps −First of all, create a data frame.Then, find the column means using colMeans function.After that, subtract column values from column means.Creating the data frameLet's create a data frame as shown below −> x1 x2 x3 df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −   x1  x2  x3 1  54  73  57 2  79  52  92 3  87  51  47 4  13  12   1 5  70  90  19 6  15  99   ...

Read More

How to create violin plot for categories with grey color palette using ggplot2 in R?

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

To create violin plot for categories with grey color palette using ggplot2, we can follow the below steps −First of all, create a data frame.Then, create the violin plot for categories with default color of violins.Create the violin plot for categories with color of violins in grey palette.Creating the data frameLet's create a data frame as shown below −> Group Score df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −     Group  Score 1   Second   405 2    Third   947 3    First    78 4 ...

Read More

How to convert data frame values to their rank in R?

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

To convert data frame values to their rank in R, we can follow the below steps −First of all, create a data frame.Then, find the rank of each value using rank function with lapply.Create the data frameLet's create a data frame as shown below −> x1 y1 df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −           x1          y1 1  -0.9045608  1.95315551 2  -1.6222122 -1.19880638 3   0.8618855 -0.33643175 4  -0.3547085 -0.18097356 5  -0.3043621 -0.60342210 6   0.5606001 -0.83618995 7  -1.1752752 -0.46651702 ...

Read More

How to find the critical value of F for regression anova in R?

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

To find the critical value of F for regression anova in R, we can follow the below steps −First of all, create a data frame.Then, create the regression model.After that, find the critical value of F statistic using qf function.Create the data frameLet's create a data frame as shown below −> x y df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −   x y 1  5 5 2  0 9 3  1 3 4  3 5 5  2 5 6  2 4 7  3 6 8  4 6 9 ...

Read More

How to set the position of legend of a ggplot2 graph to left-top side in R?

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

To set the position of legend of a ggplot2 graph to left-top side in R, we can follow the below steps −First of all, create a data frame.Then, create a plot using ggplot2 with legend.After that, add theme function to the ggplot2 graph to change the position of legend.Create the data frameLet's create a data frame as shown below −> x y Grp df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −          x          y     Grp 1   1.534536456  1.16096642 ...

Read More

How to remove row that contains maximum for each column in R data frame?

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

To remove row that contains maximum for each column in R data frame, we can follow the below steps −First of all, create a data frame.Then, remove the rows having maximum for each column using lapply and which.max function.Create the data frameLet's create a data frame as shown below −> x1 x2 df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −   x1 x2 1  9  10 2  1  9 3  8  9 4  7  6 5  4 10 6  4  7 7  8  8 8  5 13 9  4 ...

Read More
Showing 141–150 of 1,740 articles
« Prev 1 13 14 15 16 17 174 Next »
Advertisements