Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 115 of 196

How to create a matrix with vectors as elements in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 23-Nov-2021 829 Views

To create a matrix with vectors as elements in R, we can create arrays because an array contains matrices with vectors as elements.Check out the below given examples of arrays and vectors extracted by the arrays to understand how matrices stored in an array represent vectors as elements.Example 1Following snippet creates arrays consisting of matrices −Array

Read More

How to create a vertical line in a time series plot in base R?

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

To create a time series plot, we can use simply apply plot function on time series object and if we want to create a vertical line on that plot then abline function will be used with v argument.For example, if we have a time series object called T and we want to create a time series plot of T with vertical line at point 5 then we can use the below given command after creating the plot −abline(v=5)ExampleTo create a vertical line in a time series plot in base R, use the following code −x

Read More

How to convert matrices stored in a list into vectors in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 23-Nov-2021 247 Views

A list may contain vectors, data frames, matrices, lists etc. If a list contains matrices and we want to convert those matrices into vectors then lapply function can be used along with as.vector function.For example, if we have a list called LIST that contains matrices then we can convert those matrices into data frames by using the below given command − lapply(LIST,function(x) as.vector(x))ExampleFollowing snippet creates the matrices −M1

Read More

How to create a column with ratio of two columns in R?

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

To create a new column with ratio of two columns in an R data frame, we can use division sign.For example, if we have a data frame called df that contains two columns say X and Y and we want to create a new column with ratio of X and Y then we can use the below given command −df$Ratio_X_Y

Read More

How to find the number of times a variable changes its sign in an R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 23-Nov-2021 541 Views

To find the number of times a variable changes its sign in an R data frame column, we can use sign function with diff and sum function.For example, if we have a data frame called df that contains a column say C then, we can find the number of times C changes its sign by using the following command −sum(diff(sign(df$C))!=0)Example 1Following snippet creates a sample data frame −x

Read More

How to change the color of line in xyplot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 587 Views

To change the color of line in xyplot, we can use col argument.For example, if we have two vectors say X and Y and we want to create a red colored xyplot between X and Y then we can use the following command −xyplot(x~y,type="l", col="red")Check out the below example to understand how it works.ExampleTo change the color of line in xyplot, use the code given below −set.seed(123) library(lattice) xyplot(1:5~rpois(5,5),type="l",col="blue")OutputIf you execute the above given code, it generates the following output −

Read More

How to display outliers in boxplot with different shape in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 802 Views

To display outliers in boxplot with different shape in base R, we can use outpch argument in boxplot.For example, if we have a vector called X that contains some outliers then we can create a boxplot of X with different shape of outliers by using the below given command −boxplot(X,outpch=17)ExampleTo display outliers in boxplot with different shape in base R, use the code given below −x

Read More

How to change the color of box of boxplot in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 13K+ Views

To change the color of box of boxplot in base R, we can use col argument inside boxplot function.For example, if we have a vector called V and we want to create a boxplot of V without red colored box then we can use the following command −boxplot(x,col="red")ExampleTo change the color of box of boxplot in base R, use the code given below −x

Read More

How to change the color of outliers in base R boxplot?

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

To change the color of outliers in base R boxplot, we can use outcol argument in boxplot function.For example, if we have a vector called X that contains some outliers then we can create a boxplot of X with blue color outliers by using the below given command −boxplot(X,outcol="red")ExampleTo change the color of outliers in base R boxplot, use the code given below: −x

Read More

How to test if strings stored in a vector are present in an R list?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 22-Nov-2021 194 Views

To test if strings stored in a vector are present in an R list or not, we can use mapply function. For example, if we have a vector of strings say V and a list called LIST then we can check whether elements in V are present in LIST by using the following command − mapply(`%in%`,V,LIST)Example 1Following snippet creates a vector and list −x

Read More
Showing 1141–1150 of 1,958 articles
« Prev 1 113 114 115 116 117 196 Next »
Advertisements