Nizamuddin Siddiqui has Published 2307 Articles

How to delete rows of an R data frame based on string match?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:32:18

1K+ Views

Often, we need to subset our data frame and sometimes this subsetting is based on strings. If we have a character column or a factor column then we might be having its values as a string and we can subset the whole data frame by deleting rows that contain a ... Read More

How to convert a matrix to a data frame with column names and row names as new columns in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:30:43

2K+ Views

Sometimes we want to create a factor column of the column names and row names of a matrix so that we can use them in the analysis. It is required in situations where we want to know the effect of factor variables on the response and the factor variables were ... Read More

How to remove the boxes around legend of a plot created by ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:29:10

2K+ Views

When we create a plot with legend using ggplot2, the legend values are covered with a box and that makes an impact on the smoothness of the plot. These boxes around the legend values can be removed so that complete the chart becomes more appealing to the viewer and it ... Read More

How to put labels on a scatterplot that is created plot function in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:25:19

84 Views

Labelling of points on a scatterplot helps us to identify the pair of observations. For example, if we are plotting weight and height of people then we can label it with person’s name, therefore, we will be able to understand which pair of points belong to which person. This can ... Read More

How to cbind vectors of different length without repetition of elements of the smaller vector in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:21:48

811 Views

We can join vectors by columns using cbind and it does not matter whether these vectors are of same length or not. If the vectors are of same length then all the values of both the vectors are printed but if the length of these vectors are different then the ... Read More

How to merge data frames by row names in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:19:15

725 Views

Mostly, we merge the data frames by columns because column names are considered prominent in data sets but it is also possible to merge two data frames by using rows. Merging by rows is likely to result in more uncleaned data as compared to the merging by columns. This can ... Read More

How to select of data.table based on substring of row values for a column in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:16:03

369 Views

We often create subsets of data in R to perform calculations based on smaller objectives of a whole objective in data analysis projects. Sometimes this subsetting is conditional on strings instead of numeric values. We can also create a subset of data.table on the basis of substring of row values ... Read More

How to write a common title for par(mfrow) plots in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:12:10

1K+ Views

We can create multiple plots using par(mfrow) on a single plot window in R. It might be possible that all of these plots are different or same as well. Irrespective of the type of plots, we can give a common title to all the plots. This can be a situation ... Read More

How to remove all text from a string before a particular character in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:06:57

2K+ Views

Sometimes we want to extract a sub-string from a big string and that sub-string lies after a particular character. For example, a string could be “Learning.Computer.Science.is.not.difficult-Author” and we want to extract the word Author from it. This can be done with the help of gsub function.Examplesx1Read More

How to rename the factor levels of a factor variable by using mutate of dplyr package in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 21-Aug-2020 12:04:07

1K+ Views

We know that a factor variable has many levels but it might be possible that the factor levels we have are not in the form as needed. For example, if we want to have capital letters as a factor level but the original data has small letters of English alphabets. ... Read More

Advertisements