Programming Articles

Page 15 of 2545

How to convert MANOVA data frame for two-dependent variables into a count table in R?

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

MANOVA refers to multivariate analysis of variance, in this method we have more than one dependent variable and multiple independent variables. We want to compare each level of the independent variable combination for each of the dependent variables. To convert MANOVA data frame for two-dependent variables into a count table, we can use cast function of reshape package but we need to melt the data frame first so that the casting can be done appropriately.ExampleID

Read More

Sort the words in lexicographical order in C#

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 1K+ Views

Firstly, set a string array −string[] arr = new string[] {    "Indian",    "Moroccon",    "American", };To sort the words in lexicographical order −var sort = from a in arr orderby a select a;Exampleusing System; using System.Linq; class Program {    static void Main() {       string[] arr = new string[] {          "Indian",          "Moroccon",          "American",       };       var sort = from a in arr       orderby a       select a;       foreach(string res in sort) {          Console.WriteLine(res);       }    } }outputAmerican Indian Moroccon

Read More

How to view the complete output of tibble in R?

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

Tibbles are created when we analyze data using dplyr package and if the data size is large then only 10 values are printed in R. If we want to display the complete output of tibble then View function needs to be used. For example, if we want to perform calculation of counts then we should add View() at the end of the code with pipe operator.Exampledf%>%group_by(Group,Rating)%>%mutate(count=n())%>%View()Output

Read More

How to convert a data frame row into character vector in R?

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

To create a character vector in R we can enclose the vector values in double quotation marks but if we want to use a data frame row values to create a character vector then as.character function can be used. For example, if we have a data frame df then the values in first row of the df can form a character vector using as.character(df[1,]).ExampleG1

Read More

Program to find contiguous intervals of a unique array in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 745 Views

Suppose we have a list of unique numbers called nums. We have to find a sorted 2D matrix of numbers where each list represents an inclusive interval summarizing number that are contiguous in nums.So, if the input is like nums = [10, 11, 12, 15, 16, 17, 28, 30], then the output will be [[10, 12], [15, 17], [28, 28], [30, 30]], as in the list [10 to 12], [15 to 17] are contiguous, and 28 and 30 are there, they are represented as [28 to 28] and [30 to 30].To solve this, we will follow these steps−sort the list ...

Read More

How to italicize boxplot label in R using ggplot2?

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

Like every other tool for statistical analysis R does not display the labels of a boxplot in italics, thus if we want to do this, we need to do it manually. In ggplot2, we have a function scale_x_discrete that can be used to change the default font to italic using expression function.Exampleggplot(df,aes(x,y))+geom_boxplot()+scale_x_discrete(labels=expression(italic(Female),italic(Male)))Output

Read More

How to change the font size of legend in base R plot?

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

In base R, we can use legend function to add a legend to the plot. For example, if we want to create a histogram with legend on top-right position then we can use legend("topright",legend="Normal Distribution") and if we want to change the font size then we need to as cex argument as shown below:legend("topright",legend="Normal Distribution",cex=2)Examplelegend("topleft",legend="Histogram of",cex=1.5)Output

Read More

How to replace missing values with median in an R data frame column?

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

To replace missing values with median, we can use the same trick that is used to replace missing values with mean. For example, if we have a data frame df that contain columns x and y where both of the columns contains some missing values then the missing values can be replaced with median as df$x[is.na(df$x)]

Read More

How to create scatterplot for factor levels in an R data frame?

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

To create a scatterplot for factor levels, we can use facet_grid function of ggplot2 package. For example, suppose we have a factor column in a data frame df defined as F and numerical columns defined as x and y then the scatterplot for the factor levels can be created as −ggplot(df,aes(x,y))+geom_point()+facet_grid(~Factor)Examplelibrary(ggplot2) ggplot(df,aes(x,y))+geom_point()+facet_grid(~Factor)Output

Read More

How to change the Y axis limit for boxplot created by using ggplot2 in R?

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

One of the most important aspects of a boxplot is Y-axis labels because these labels help us to understand the limit of the variable. Since R generate these labels automatically in a good way, we stick with that but we can change that using coord_cartesian function with ylim as shown in the below example.Exampleggplot(df,aes(x,y))+geom_boxplot()+coord_cartesian(ylim=c(290,400))Output

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