Nizamuddin Siddiqui has Published 2307 Articles

How to replace NA with 0 and other values to 1 in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Feb-2021 12:45:30

604 Views

Sometimes we want to convert a column of an R data frame to binary column using 0 and 1, it is especially done in situations where we have some NAs in the column of the data frame and the other values can be converted to 1 due to some characteristics. ... Read More

How to create the plots arranged in a list that were generated using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Feb-2021 12:45:22

411 Views

If we have two plots generated by using ggplot2 and arranged in a list then we can create them using ggarrange function. For example, if we have two objects p1 and p2 that are stored in the list called named as LIST then those plots can be created in the ... Read More

What is the use of set.seed in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Feb-2021 12:43:35

819 Views

The set.seed helps to create the replicate of the random generation. If the name of the object changes that does not mean the replication will be changed but if we change the position then it will. Here, in the below example x4 in the first random generation and the x_4 ... Read More

How to check the least number of arguments a function expects in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Feb-2021 12:43:21

122 Views

To find the least number of arguments a function expects while using in R can be done with the help of the syntax: length(formals(“function_name”)). For example, to find the number of arguments expected by mutate function of dplyr package can be calculated by using the command length(formals(mutate)) but we need ... Read More

How to find the extremes of a data frame column in R if infinity exists in the column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Feb-2021 12:43:10

184 Views

To find the extremes of a data frame column that is numeric can be done with the help of min and max function but if we want to get the same in single line code then range function can be used. If there are some infinity values in the column ... Read More

How to display star for significance in base R boxplot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Feb-2021 12:42:57

3K+ Views

To display the star for significance in a base R boxplot, we can use text function. The text function will be helpful in defining the star sign (that is asterisk or *). If the significance is high then three stars are used and the significance is low then a single ... Read More

How to create the stacked bar plot using ggplot2 in R with labels on the plot?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Feb-2021 12:42:38

2K+ Views

The creation of stacked bar plot using ggplot2 can be done with the help of position="stack" argument inside geom_bar function. If we want to create the stacked bar plot then geom_text function will be used with the same position argument and the aes to define the labels as shown in ... Read More

How to save a plot in pdf in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Feb-2021 12:07:20

4K+ Views

To save a plot in pdf, we can use the pdf function in base R. For example, if we want to save a plot with the name PDF then it can be done using the below command −pdf("PDF.pdf")After this we can create the plot and use dev.off().Examplepdf("pdfExample.pdf") plot(1:10)OutputExample Live Demodev.off()OutputTo check ... Read More

How to select positive values in an R data frame column?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Feb-2021 12:06:22

1K+ Views

We know that positive values are greater thandf1$x[which(df1$x>0)]Example1 Live Demoset.seed(254) x

How to convert columns of an R data frame into a single vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Feb-2021 11:53:14

1K+ Views

Sometimes all the columns in a data frame have similar data characteristics representing a particular variable. For example, having a data frame containing five columns each with heights of people. To convert this type of data frame into a vector we can use as.vector function along with the as.matrix function. ... Read More

Advertisements