R Programming Articles

Page 5 of 174

How to create a boxplot using ggplot2 for single variable without X-axis labels in R?

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

The important part of a boxplot is Y−axis because it helps to understand the variability in the data and hence, we can remove X−axis labels if we know the data description. To create a boxplot using ggplot2 for single variable without X−axis labels, we can use theme function and set the X−axis labels to blank as shown in the below example.Exampleggplot(df,aes(x=factor(0),y))+geom_boxplot()+theme(axis.title.x=element_blank(),axis.text.x=element_blank(),axis.ticks.x=element_blank())Output

Read More

How to perform shapiro test for all columns in an R data frame?

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

The shapiro test is used to test for the normality of variables and the null hypothesis for this test is the variable is normally distributed. If we have numerical columns in an R data frame then we might to check the normality of all the variables. This can be done with the help of apply function and shapiro.test as shown in the below example.Exampleapply(df, 2, shapiro.test)Output$x1 Shapiro-Wilk normality test data: newX[, i] W = 0.94053, p-value = 0.2453 $x2 Shapiro-Wilk normality test data: newX[, i] W = 0.95223, p-value = 0.4022 $x3 Shapiro-Wilk normality test data: newX[, i] W = ...

Read More

How to divide the data frame rows in R by row standard deviation?

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

To divide the data frame row values by row standard deviation in R, we can follow the below steps −First of all, create a data frame.Then, use apply function to divide the data frame row values by row standard deviation.Creating 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   1.48  0.86 2  -0.14 -0.58 3  -0.25  1.22 4   0.18  0.25 5   0.50  0.68 6  -1.34 -0.21 ...

Read More

How to create a sample or samples using probability distribution in R?

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

A probability distribution is the type of distribution that gives a specific probability to each value in the data set. For example, if we have a variable say X that contains three values say 1, 2, and 3 and each of them occurs with the probability defined as 0.25, 0.50, and 0.25 respectively then the function that gives the probability of occurrence of each value in X is called the probability distribution. In R, we can create the sample or samples using probability distribution if we have a predefined probabilities for each value or by using known distributions such as ...

Read More

How to subset a named vector based on names in R?

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

To subset a named vector based on names, we can follow the below steps −Create a named vector.Subset the vector using grepl.Create the named vectorLet’s create a name vector as shown below −V

Read More

How to set the number of digits to be printed for summary command without using options(digits) in R?

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

To set the nuber of digits to be printed for summary command without using options(digits), we can use digits argument while printing the summary. −Example 1Using mtcars data and finding the summary statistics with number of digits set to 2 −summary(mtcars, digits=2)On executing, the above script generates the below output(this output will vary on your system due to randomization) −Output   mpg             cyl            disp            hp          drat Min.   :10    Min.   :4.0    Min.   : 71    Min.   ...

Read More

How to find the summary by categorical variable in R?

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

To find the summary by categorical variable, we can follow the below steps −Use inbuilt data sets or create a new data set.Find the summary statistics with by function.Use inbuilt data setLet’s consider mtcars data set in base R −data(mtcars) head(mtcars, 25)On executing, the above script generates the below output(this output will vary on your system due to randomization) −                      mpg  cyl disp   hp  drat   wt   qsec vs am gear carb Mazda RX4             21.0 6   160.0 110  3.90 2.620 16.46 ...

Read More

How to filter data frame by categorical variable in R?

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

To filter data frame by categorical variable in R, we can follow the below steps −Use inbuilt data sets or create a new data set and look at top few rows in the data set.Then, look at the bottom few rows in the data set.Check the data structure.Filter the data by categorical column using split function.Use inbuilt data setLet’s consider CO2 data set in base R −data(CO2) head(CO2, 10)On executing, the above script generates the below output(this output will vary on your system due to randomization) −Grouped Data: uptake ~ conc | Plant   Plant Type Treatment conc uptake 1 ...

Read More

How to print a factor vector without levels in R?

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

To print a factor vector without levels in R, we can follow the below steps −First of all, create a factor vector.Then, use as.character function to read the vector.Example 1Create a factor vectorLet’s create a vector called f1 as shown below −f1

Read More

How to limit the length of regression line using ggplot2 in R?

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

To limit the length of regression line using ggplot2 in R, we can follow the below steps −First of all, create a data frame.Then, create the scatterplot using ggplot2 with regression line.After that, create the scatterplot with regression and add xlim function.Create the data frameLet's create a data frame as shown below −x

Read More
Showing 41–50 of 1,740 articles
« Prev 1 3 4 5 6 7 174 Next »
Advertisements