Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 113 of 196

How to find the mean of every n values in an R vector?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 1K+ Views

To find the mean of every n values in an R vector, we would first need to convert the vector into matrix with number of rows based for n values then we can use colMeans function.For example, if we have a vector called X that contains hundred values then we can find the mean of every ten value by using the command given below −colMeans(matrix(X,10))Example 1To find the mean of every n values in an R vector, use the command given below −x1

Read More

How to find the most frequent factor value in an R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 15K+ Views

To find the most frequent factor value in an R data frame column, we can use names function with which.max function after creating the table for the particular column. This might be required while doing factorial analysis and we want to know which factor occurs the most.Check out the below examples to understand how it can be done.Example 1Following snippet creates a sample data frame −Factor_1

Read More

How to extract the first row of each matrix stored in a list in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 1K+ Views

To extract the first row of each matrix stored in a list in R, we can use lapply function. For example, if we have a list called LIST that contains some matrices then we can find the first row of each matrix by using the command given below − lapply(LIST,'[',1,)Check out the below given example to understand how it can be done.ExampleFollowing snippet creates a list of matrices −M1

Read More

How to extract the outliers of a boxplot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 3K+ Views

To extract the outliers of a boxplot, we can use out function along with the boxplot function. For example, if we have a vector called X which contains some outliers then we can extract those outliers by using the command given below − boxplot(df$X, plot=FALSE)$outThis command will not create a plot as plot is set to FALSE.ExampleFollowing snippet creates a sample data frame −df=data.frame(x=rlnorm(25)) dfThe following dataframe is created −      x 1  0.5699270 2  3.5812629 3  0.3507882 4  0.1400328 5  0.7239948 6  2.5494114 7  3.1243611 8  5.3207739 9  0.1672539 10 7.6235529 11 0.4950263 12 1.1713592 13 1.6590328 14 ...

Read More

How to replace zero with previous value in an R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 972 Views

To replace zero with previous value in an R data frame column, we can use na.locf function of zoo package but to apply this we first need to replace the zero values with NA.For example, if we have a data frame called df that contains a column say Rate then we can use the below commands to replace 0 values in Rate with previous value by using the below given commands − df$Rate[df$Rate==0]

Read More

Create scatterplot for two dependent variables and one independent variable in R.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 2K+ Views

To create scatterplot for two dependent variables and one independent variable, we can use geom_point function and geom_smooth function of ggplot2 package. Both of these functions will be used twice, where we can define the aesthetics of the plot for each dependent variable as shown in the Example below.ExampleFollowing snippet creates a sample data frame −x

Read More

Create line chart for mean covered with minimum and maximum in R.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Nov-2021 1K+ Views

To create line chart for mean covered with minimum and maximum in R, we first need to create columns for row means, row minimum, and row maximum after that geom_line function can be used along with geom_ribbon function of ggplot2 package as shown in the below example.ExampleFollowing snippet creates a sample dataframe.x

Read More

How to add two columns if both contains missing values in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Nov-2021 1K+ Views

If we want to add two columns of an R data frame and each of them contains missing values then the addition of columns can be done in one of the following ways −Adding both the column values if they are numeric.Returning numeric if one of the columns has missing value.Returning NA if both the columns have missing value.To this we can take help of apply function and ifelse function as shown in the below given examples.Example 1Following snippet creates a sample data frame −x1

Read More

How to take transpose of vectors stored in an R list?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Nov-2021 330 Views

We can take the transpose of vectors stored in an R list by using Map function with do.call. For example, if we have a list called LIST that contains say ten vectors then we can transpose these vectors by using the command given below − do.call(Map,c(f=c,LIST))Check out the below examples to understand how it works.Example 1To take transpose of vectors stored in an R list, use the command given below −List1

Read More

How to subset a matrix based on values in a particular column in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Nov-2021 3K+ Views

To subset a matrix based on values in a particular column, we can use single square brackets and provide the row and column values. The column values will be set for the columns that we want to subset and the row value will be set for the values of the column using which we want to subset the matrix.Check out the below example to understand how it works.ExampleFollowing snippet creates a matrix −M

Read More
Showing 1121–1130 of 1,958 articles
« Prev 1 111 112 113 114 115 196 Next »
Advertisements