Nizamuddin Siddiqui has Published 2307 Articles

How to create data frame using nested list elements in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 11:48:00

359 Views

To create data frame using nested list elements, we would need to unlist the list elements and store them in a matrix then read as a data frame using data.frame function. For example, if we have a nested called LIST then the data frame can be created by using the ... Read More

How to subset an R data frame based on string match in two columns with OR condition?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 11:42:33

892 Views

To subset an R data frame based on string match in two columns with OR condition, we can use grepl function with double square brackets and OR operator |. For example, if we have a data frame called df that contains two string columns say x and y then subsetting ... Read More

How to change default point size of geom_point in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 11:37:41

341 Views

To change the default point size of geom_point, we need to use update_geom_defaults function. Specifically, for the change of point size the syntax will be as follows −update_geom_defaults("point", list(size=”value”))Here, we can change the value according to our need.ExampleConsider the below data frame − Live DemoxRead More

How to find the proportion of each value for a cross tab obtained from a data frame in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 11:33:10

802 Views

To find the proportion of each value for a cross tab obtained from a data frame, we can use prop.table function. Suppose we have a data frame called df that contains three columns, two categorical say C1 and C2 and one numerical say Y then the cross tab will be ... Read More

How to change the point size in geom_point conditionally in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 11:24:20

2K+ Views

To change the point size in geom_point conditionally, we can define the condition in geom_point with aes and the size using scale_size_manual function of ggplot2 package. For example, if we have a data frame called df that contains two columns say x and y then the scatterplot with different size ... Read More

How to create a list of regression models for predefined vectors in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 11:23:20

2K+ Views

To create a list of regression models for predefined vectors, we can create a blank list and then use the for loop to create the list of regression models. For example, if we have two vectors say x and y, and we want to create a list of regression model ... Read More

How to add approximately equal sign in a plot using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 11:22:11

358 Views

To add approximately equal sign in a plot using ggplot2, we can use tilde sign twice as ~~ in geom_text function of ggplot2 package. For example, we can do this by using the following syntax geom_text(aes(label="NULL%~~%")). Check out the below example to understand how it works.ExampleConsider the below data frame ... Read More

How to display the data frame summary in vertical order in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:29:23

319 Views

To display the data frame summary in vertical order, we can use lapply and cbind function along with the summary function. For example, if we have a data frame called df then the summary of df in vertical order can be found by using the below command −lapply(df, function(x) cbind(summary(x)))Example1Consider ... Read More

How to select rows of an R data frame that are non-NA?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 06-Mar-2021 05:27:42

8K+ Views

To select rows of an R data frame that are non-Na, we can use complete.cases function with single square brackets. For example, if we have a data frame called that contains some missing values (NA) then the selection of rows that are non-NA can be done by using the command ... Read More

How to create stacked plot with density using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

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

323 Views

To create stacked plot with density using ggplot2, we can use geom_density function of ggplot2 package and position="stack". For example, if we have a data frame called df that contains two columns say x and y, where x is categorical and y is numerical then the stacked plot with density ... Read More

Advertisements