Nizamuddin Siddiqui has Published 2307 Articles

How to create a row sum and a row product column in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 07:45:36

331 Views

To create a row sum and a row product column in an R data frame, we can use rowSums function and the star sign (*) for the product of column values inside the transform function. For example, if we have a data frame df that contains x, y, z then ... Read More

How to create an exponential curve in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 07:44:37

4K+ Views

To create an exponential curve, we can use exp function inside the plot function for the variable that we want to plot. For example, if we have a vector x then the exponential curve for the vector x can be created by using plot(x, exp(x)). We can use the exponential ... Read More

How to create a staircase plot in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 07:43:03

467 Views

The simple staircase plot can be created by using geom_tile function of ggplot2 package. We just need to use the vector or the column for which we want to create the staircase plot in place of x and y as well. For example, if we have a column say x ... Read More

How to create colored barplot using ggplot2 without legend entries in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 07:41:32

84 Views

When we create a colored barplot using ggplot2 the legend entries are automatically created. If we want to create the plot without those legend entries then theme function can be used. For example, if we have a data frame df that contains x as categorical variable and y as count ... Read More

How to create a point chart for categorical variable in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 07:40:16

358 Views

The point chart of a categorical has points corresponding to the categories just like the bar chart has bars. If we want to create point chart for categorical variable then we just need to use geom_point function of ggplot2 package. For example, if we have a data frame df that ... Read More

How to extract the first highest occurring value in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 07:39:01

133 Views

The highest occurring value is called the mode and there can be multiple modes in a variable. If we have multiple modes then we can find the first mode or first highest occurring value by using sort function. For example, if we have a vector x that contains more than ... Read More

How to count the number of values that satisfy a condition in an R vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 07:37:47

3K+ Views

Sometimes we want to find the frequency of values that satisfy a certain condition. For example, if we have a vector say x that contains randomly selected integers starting from 1 and ends at 100, in this case we might want to find how many values are exactly equal to ... Read More

How to remove a common suffix from column names in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 07:35:45

6K+ Views

To remove a common suffix from column names we can use gsub function. For example, if we have a data frame df that contains column defined as x1df, x2df, x3df, and x4df then we can remove df from all the column names by using the below command:colnames(df) x1Data x2Data x3Data ... Read More

How to find the standard deviation if NA’s are present in a column of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 07:34:26

4K+ Views

If there exists an NA in a vector or column of an R data frame, the output of the sd command for standard deviation results in NA. To solve this problem, we need to use na.rm=TRUE as we do it for vectors that do not contain missing values. For example, ... Read More

How to set the legends using ggplot2 on top-right side in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 07-Nov-2020 07:32:44

3K+ Views

The default position of legend in a plot created by using ggplot2 is right hand side but we can change the position by using theme function that has legend.position argument and legend.justification argument. To set the legend on top-right side we can use legend.position="top" and legend.justification="right".ExampleConsider the below data frame:Consider ... Read More

Advertisements