How to Calculate Trimmed Means in R (Examples)

A trimmed mean is a mean trimmed by x%, where x is the percentage of observations removed from both the upper and lower bounds. For instance, 10% trimmed mean is the mean computed by excluding th 10% largest and 10% smallest observations in the data. mean() in R has the parameter of trim, which should … Read more

Categories R

How to Use Mean() In R with Examples

mean() can be used to calculate mean in R. The following is the basic statement. mean(x, trim = 0, na.rm = FALSE) x: It is an R object.  trim: It is in the range of (0 to 0.5). The number indicates the percentage of observations to be trimmed from each end of sorted x, before the mean is computed. … Read more

Categories R

How to Plot 2-Way ANOVA Interaction in R (with Example)

This tutorial shows how to plot the figure for the interaction in 2-way ANOVA in R. Steps of Plotting 2-Way ANOVA Interaction in R Step 1: Prepare the data The following is the data being used for the examples. It has two categorical variables (i.e., City and Brand) and one continuous variable (i.e., sales). Output: … Read more

Categories R

How to Use stringsAsFactors in R

stringsAsFactors decides the strings will be considered as factors or just strings or characters. The following uses two examples to explains the difference. Example 1: stringsAsFactors= FALSE The following sets stringsAsFactors= FALSE. We can see that the data type of the column of Names is characters. (chr represents characters.) Output: Names Ages 1 Jack 32 … Read more

Categories R

How to Calculate Means by Group in R (2 Examples)

This tutorial is about how to calculate means by group in R. There are two methods of calculating means by groups in R, either aggregate() or dplyr. Method 1: Use base R aggregate(df$col_being_aggregated, list(df$col_1_groupby,df$col_2_groupby,…), FUN=mean) Method 2: Use package of dplyr library(dplyr) df%>% group_by(col_1_groupby,col_2_groupby,…) %>% summarise_at(vars(col_being_aggregated), list(name = mean)) Example for Method 1 The following … Read more

Categories R

Calculate Sum of Squares Total (SST) in R (2 Examples)

This tutorial shows how to calculate Sum of Squares Total (SST) in R. The following is the data being used. The hypothetical data being used has two categorical IVs (cities and stores) and one DV (sales). Note that, while it has two IVs, the calculation of SST actually does not need to use these two … Read more

Overview of Type I, Type II, and Type III ANOVA in R (with Examples)

This tutorial explains what Type I, Type II, and Type III ANOVA are. Further, it provides examples showing how you can do Type I, Type II, and Type III ANOVA in R. 1. Introduction Type I, Type II, and Type III ANOVA are 3 different ways of calculating sum of squares in ANOVA. Type I … Read more

Categories R

Why Type I ANOVA is Sequential Sum of Squares (R code example)

Type 1 ANOVA is also called sequential sum of squares, because it considers the order effect of entering factors into the model. If you change the order of the factors in the model, the results will be different. The following uses an example in R to explain this. Step 1: Prepare the data The following is … Read more

How to Conduct Two-Way ANOVA in R

This tutorial shows how you can do two-way ANOVA in R with examples. A two-way ANOVA is used to test whether the means from the two or more categorieal variables are significantly different from one another. For instance, below, there are two categorical variables, namely city (city 1 and city 2) and store (store 1 and store 2). … Read more

Categories R

R Vetors

Vectors are a basic data object in R. There are six types of vectors, namely logical, integer, double, complex, character and raw. You can use a c() function to create vectors, and the following shows the examples. 1. Logical Vector Output: [1] TRUE FALSE [1] “logical” 2. Integer Vector Output: [1] 44 56 [1] “integer” … Read more

Categories R