Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 160 of 196

How to create multiple plots of different sizes in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 19-Oct-2020 404 Views

Often, we have multiple values, vectors or columns of an R data frame that needs to be plotted on a single graph so that we can compare them at the same time or they have some kind of relationship among them. Therefore, we can use layout function along with matrix function to divide the plot window as shown in the below exampleConsider the below layout and plot of individual values −Examplelayout(matrix(c(1, 2, 3, 3, 4, 5, 6, 6), nrow=4, ncol=2, byrow=FALSE)) plot(500) plot(525) plot(530) plot(531) plot(540) plot(528)OutputChanging the layout and creating the plots −Examplelayout(matrix(c(1, 2, 3, 3, 4, 5, 6, ...

Read More

How to deal with warning message `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. in R while creating a histogram?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 18-Oct-2020 8K+ Views

The default value for bins is 30 but if we don’t pass that in geom_histogram then the warning message is shown by R in most of the cases. To avoid that, we can simply put bins=30 inside the geom_histogram() function. This will stop showing the warning message.Consider the below data frame −x

Read More

How to find the day of the year from dates in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Oct-2020 8K+ Views

To find the day of the year from dates, we can use yday function of lubridate package. For example, if we have a date or a date of vectors then we simply need to pass that date or the vector inside yday function by using the below syntax −yday(“date”)oryday(“vector_of_date”)Loading lubridate package −library(lubridate)Examplesdate1

Read More

How to convert a list of lists into a single list in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Oct-2020 2K+ Views

A list can contain multiple lists of different type as well as similar type elements such as data frames, vectors, matrices etcetera but accessing those elements become a little difficult task. Therefore, it is better to convert a list that contain multiple lists into a single list and it can be done using unlist function.ExampleConsider the below vectors −set.seed(871) x1

Read More

How to extract string before slash from a vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Oct-2020 2K+ Views

If a vector contains string values and they are separated with a special character (This special character can be anything, also it is not necessarily to be a special character) and we want to extract only the values that exists before that special then we can use gsub function. For example, if we have a vector x that contain "UT/YT", "IST/IT", "PST/PT" then gsub can help us to extract UT, IST, PST.Examplex1

Read More

How to extract website name from their links in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Oct-2020 270 Views

If we have a list of website links and we want to extract the website name from those links then it is a time-consuming task because we would need to copy each name one-by-one. Therefore, it is better to extract them using a function in R and save time. To extract the website name from the website link, we can use suffix_extract function of urltools package. This will extract the host, subdomain, domain and suffix. And it is known that the domain values are the website names.Loading urltools package −library(urltools)Website links stored in a vector −Web_Links

Read More

How to find the name of the author of a package in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Oct-2020 504 Views

There can be multiple authors of a package in R and we might want to use their name if we are using their package in our publication for research, books, courses or any other type of content. Therefore, it is required to find out all the authors who contributed to a particular package and this can be done by using citation function with package name as shown in the below examples.Examplecitation("ggplot2")To cite ggplot2 in publications, please use −H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016.A BibTeX entry for LaTeX users is@Book{,    author = {Hadley Wickham}, ...

Read More

How to create a predictive linear regression line for a range of independent variable in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Oct-2020 351 Views

If we want to create a regression line inside scatterplot then lines function can be used with the linear model function lm but if we want to do it for a particular range of independent variable then this range needs to be defined and passed within the lines function. Check out the below example of linear regression model that considers a range of independent variable for prediction.Consider the below vectors −Examplestrsplit(x6,"[*]")OutputDefining the range of x −Range_of_x

Read More

How to convert data.table object into a matrix in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 16-Oct-2020 395 Views

A data.table object is very similar to a data frame in R, therefore, converting a data.table object to a matrix is not a difficult job. We just need to use as.matrix function and store the data.table object into a new object that will belong to the matrix, otherwise R will not be able to convert the data.object to a matrix. For example, if we have a data.table object DT then to convert it into a matrix, we should use the below example code −DT_matrix

Read More

How to create a line chart in R using plot function with larger width?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 14-Oct-2020 229 Views

To create a line chart in base R using plot function, we need to use type = "l" so that R understand the plot needs to have a line instead of points. If we want to increase the width of the line then lwd argument can be used. The value lwd = 0 is the default value for the width.Consider the below vector and create the line chart −Examplex

Read More
Showing 1591–1600 of 1,958 articles
« Prev 1 158 159 160 161 162 196 Next »
Advertisements