Nizamuddin Siddiqui has Published 2307 Articles

How to find the position of one or more values in a vector into another vector that contains same values in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Oct-2020 15:33:10

584 Views

Finding the position of one of more values that are common in two vectors can be easily done with the help of match function. The match function will match the values in first and second vector then return the index or position of these common values in second vector.Example Live Demoset.seed(145) ... Read More

How to plot values with log scales on x and y axis or on a single axis in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Oct-2020 15:30:33

3K+ Views

We can plot numerical values in R with many scales and that includes log scale as well. Also, it is possible to plot the values with log scales on both the axes. In base R, the best way to do this is defining the axes values with decimal representation as ... Read More

How to set a level of a factor column in an R data frame to NA?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Oct-2020 15:28:27

631 Views

In data analysis, we often face inappropriate data and hence the data analysis becomes difficult. An example of inappropriate data is reading missing values with a different value by naming them as Missing or Not Available. It can be done by using below syntax −Syntaxlevels(“data_frame_name”$”Column_name”)[levels(“data_frame_name”$”Column_name”=="Missing"]Read More

How to create a subset based on levels of a character column in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Oct-2020 15:22:03

1K+ Views

In R programming, mostly the columns with string values can be either represented by character data type or factor data type. For example, if we have a column Group with four unique values as A, B, C, and D then it can be of character or factor with four levels. ... Read More

How to check whether a data frame exists or not in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Oct-2020 15:17:31

2K+ Views

Sometimes we keep writing codes in the programming console and suddenly we need to use something that was used in the upper side of programming console then recalling it becomes a little ambiguous if we forget about it. In this case, we might want to check whether something exists or ... Read More

How to find the rank of a matrix in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Oct-2020 15:14:24

7K+ Views

The rank of a matrix is defined as the maximum number of linearly independent vectors in rows or columns. If we have a matrix with dimensions R x C, having R number of rows and C number of columns, and if R is less than C then the rank of ... Read More

How to find the sum of corresponding elements in multiple vectors even if they contain NA’s in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Oct-2020 15:05:29

223 Views

If we have multiple vectors then the sum of the corresponding elements can be found by using rowSums functions and the vectors can be combined by using cbind so that R can easily read the corresponding elements. But if there are NA values in one or more vectors then we ... Read More

How to renumber rows if they are unordered in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Oct-2020 15:03:32

370 Views

When we create a sample using inbuilt or imported data set then the numbering for selected rows as in the original data set, therefore, the numbering becomes unordered. To change this unordered numbering to a sequence say starting from one to the total number of rows in the sample, we ... Read More

How to create two plots using ggplot2 arranged in a vertical manner in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Oct-2020 14:54:43

491 Views

The two plots created by using ggplot2 can be arranged in a vertical manner with the help gridExtra package, we simply needs to use grid.arrange function to do so. For example, if we have two plots created by using ggplot2 and saved in objects p1 and p2 then they can ... Read More

How to create barplot from data frame in R using rows as categories?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 09-Oct-2020 14:51:45

6K+ Views

If we have small number of rows then we might want to create bar plot for rows instead of using columns as categories. This can be done by using barplot function but we need to convert the data frame to matrix and take the transpose of it. For example, if ... Read More

Advertisements