Nizamuddin Siddiqui has Published 2307 Articles

How to extract the last element in an R matrix?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 11:40:07

551 Views

To extract the last element in an R matrix, we can use the length function along with single square brackets that are used for subsetting. For example, if we have a matrix called M as shown below −M1 2 3 4 5 6 7 8 9then we can extract last ... Read More

How to extract data frame columns stored in a list in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 11:35:36

3K+ Views

Suppose we have two frames each having 5 columns that are stored in a list in R and the data that belongs to same columns has some kind of inherent relationship or we want to check whether there exists a relationship between them then we might want to extract those ... Read More

How to remove starting and ending zeros in an R vector?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 11:31:54

518 Views

To remove starting and ending zeros in an R vector, we can use min and max function to access values except 0 and then subsetting with single square brackets. For example, if we have a vector called x then we can remove starting and ending zeros by using the command ... Read More

How to remove rows that contain at least one 0 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 11:29:13

3K+ Views

To remove rows that contain at least one 0, we can use single square brackets for subsetting rows with apply that will select rows that do not contain even one zero. For example, if we have a data frame called df then we can remove rows that contain at least ... Read More

How to split a data frame using row number in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 11:25:37

1K+ Views

To split a data frame using row number, we can use split function and cumsum function. The split function will split the rows and cumsum function will select the rows. For example, if we have a data frame called df that contains twenty rows then we can split into two ... Read More

How to check if a vector exists in a list in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 11:17:43

4K+ Views

To check if a vector exists in a list, we can use %in%, and read the vector as list using list function. For example, if we have a list called LIST and a vector called V then we can check whether V exists in LIST using the command LIST %in% ... Read More

How to display mean in a boxplot with cross sign in base R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 11:14:20

285 Views

To display mean in a boxplot with cross sign in base R, we can use the points function and pass the mean with pch = 4 that represents a star, also we can change the color to highlight the mean using col argument and the size of the start can ... Read More

How to select columns in R without missing values?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 11:09:52

2K+ Views

There are two easy methods to select columns of an R data frame without missing values, first one results in a vector and other returns a matrix. For example, if we have a data frame called df then the first method can be used as df[, colSums(is.na(df))==0] and the second ... Read More

How to display tick marks on upper as well as right side of the plot using ggplot2 in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 11:05:36

481 Views

To display tick marks on upper as well as right side of the plot, we can create duplicate axes for X as well Y by using scale_x_continuous and scale_y_continuous functions. The argument that will help us in this case is sec.axis and we need to set it to dup_axis as ... Read More

How to divide each column by a particular column in R?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 16-Mar-2021 11:02:17

12K+ Views

To divide each column by a particular column, we can use division sign (/). For example, if we have a data frame called df that contains three columns say x, y, and z then we can divide all the columns by column z using the command df/df[, 3].ExampleConsider the below ... Read More

Advertisements