Nizamuddin Siddiqui has Published 2307 Articles

How to create a plot using ggplot2 by including values greater than a certain value in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:24:47

2K+ Views

To create a plot using ggplot2 by excluding values greater than a certain value, we can use subsetting with single square brackets and which function. For example, if we have a data frame called df that contains two columns say x and y, then the point chart by including values ... Read More

How to make a plot title partially bold using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:24:05

3K+ Views

To make a plot title partially bold using ggplot2, we can use bquote function inside labs function and then changing the default font to bold using bold function as shown in the below examples. While using these functions we need to make sure that the title that we want to ... Read More

How to calculate monthly average for time series object in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:19:20

3K+ Views

To calculate monthly average for time series object, we can use tapply function with mean. For example, if we have a time series object called TimeData then the monthly average for this series can be found by using the command tapply(TimeData, cycle(TimeData), mean).Example1Consider the below time series object −Live Demo> ... Read More

How to find the column that has the largest sum in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:16:19

402 Views

To find the column that has the largest sum, we can use sort function for sorting in decreasing order with colSums and accessing the first element of the output which will be the largest sum. For example, if we have a data frame called df that contains multiple columns then ... Read More

How to convert a column with missing values to binary with 0 for missing values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:14:48

222 Views

To convert a column with missing values to binary with 0 for missing values, we can use as.integer function with complete.cases for the data frame column. For example, if we have a data frame called df that contains a column x which has some missing values then the column x ... Read More

How to extract the last row from list of a data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:14:17

458 Views

Suppose we have two frames each having 5 columns that are stored in a list in R and we want to extract the last row from each data frame then we can use the lapply function. For example, if we have a list called LIST that contains the data frames ... Read More

How to find the number of unique values in each row of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:12:08

1K+ Views

To find the number of unique values in each row of an R data frame, we can use apply function with length and unique function. For example, if we have a data frame called df that contains multiple columns then the number of unique values in each row of df ... Read More

How to apply a manually created function to two columns in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:10:12

556 Views

Suppose we created a function that can take two different values at a time then we can apply that function to two columns of an R data frame by using mapply. For example, if we have a manually created function say func that multiply two values then we can apply ... Read More

How to create a histogram without bins in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:08:49

286 Views

We can set type argument to s in plot function to create a histogram without bins but first we need to create the histogram and store it in an object. For example, if we have a vector say x then the histogram of x can be stored in an object ... Read More

How to change the order of boxplot by means using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:08:18

653 Views

To change the order of boxplot by means using ggplot2, we can use reorder function inside aes of ggplot. For example, if we have a data frame called df that contains two columns say x (categorical) and y(count) then the boxplot ordered by means can be created by using the ... Read More

Advertisements