Nizamuddin Siddiqui has Published 2303 Articles

How to subset factor columns in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 06:14:42

835 Views

Subsetting of factor columns can be done by creating an object of all columns using sapply with is.factor to extract only factor column in the future then passing that object into subsetting operator single square brackets. For example, if we have a data frame df that contains three columns x, ... Read More

How to create a scatterplot using ggplot2 with different shape and color of points based on a variable in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 17-Oct-2020 06:08:32

573 Views

In general, the default shape of points in a scatterplot is circular but it can be changed to other shapes using integers or sequence or the variable. We just need to use the argument shape inside geom_point function and pass the variable name. For example, if we want to create ... Read More

How to remove the row names or column names from a matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Oct-2020 15:50:58

23K+ Views

To remove the row names or column names from a matrix, we just need to set them to NULL, in this way all the names will be nullified. For example, if we have a matrix M that contain row names and column names then we can remove those names by ... Read More

How to replicate a matrix by rows in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Oct-2020 15:35:03

3K+ Views

The replication of matrix by rows means that repeating a matrix one or more times but row-wise. For example, if we have a matrix that contains only one row and three columns then the replication of that matrix three times will repeat that one row three times. This can be ... Read More

How to extract website name from their links in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Oct-2020 15:25:38

251 Views

If we have a list of website links and we want to extract the website name from those links then it is a time-consuming task because we would need to copy each name one-by-one. Therefore, it is better to extract them using a function in R and save time. To ... Read More

How to create horizontal line for a range of values in a plot created by using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Oct-2020 15:22:49

641 Views

To display a particular part of independent variable in a plot, we might want to use a horizontal line. This will make the plot look different and get the attention of the viewer. To create a horizontal line in a plot, we can use geom_line function but we need to ... Read More

How to remove underscore from column names of an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Oct-2020 15:20:06

3K+ Views

When we import data from outside sources then the header or column names might be imported with underscore separated values and this is also possible if the original data has the same format. Therefore, to make the headers shorter and look better we would prefer to remove the underscore sign ... Read More

How to find the row-wise frequency of zeros in an R data frame?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Oct-2020 15:13:03

1K+ Views

In data analysis, we need to be very cautious about repeated values because they might be inputted purposely to create bias in the data and this value could be a zero as well. It happens in situations when we have missing data and the data collector replaces missing values with ... Read More

How to represent all values of X-axis or Y-axis on the graph in R using ggplot2 package?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Oct-2020 15:03:52

7K+ Views

If we have many unique elements or repeated in a column of an R data frame and create a graph using that column, either on X-axis or Y-axis then R automatically choses the axes labels, this might not display all the unique values of the column in the plot. Therefore, ... Read More

How to find the name of the author of a package in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Oct-2020 15:01:28

474 Views

There can be multiple authors of a package in R and we might want to use their name if we are using their package in our publication for research, books, courses or any other type of content. Therefore, it is required to find out all the authors who contributed to ... Read More

Advertisements