Articles on Trending Technologies

Technical articles with clear explanations and examples

How to select a column of a matrix by column name in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 24-Aug-2020 3K+ Views

When we create a matrix in R, its column names are not defined but we can name them or might import a matrix that might have column names. If the column names are not defined then we simply use column numbers to extract the columns but if we have column names then we can select the column by name as well as its name.Example1M1

Read More

How to draw a violin plot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 24-Aug-2020 596 Views

A violin plot is similar to a boxplot but looks like a violin and shows the distribution of the data for different categories. It shows the density of the data values at different points. In R, we can draw a violin plot with the help of ggplot2 package as it has a function called geom_violin for this purpose.ExampleConsider the below data frame −set.seed(1) x

Read More

What is the difference between order and rank function in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 24-Aug-2020 1K+ Views

The rank function gives the rank of the values in a vector if the vector is sorted but in the same sequence as the original vector and the order function gives the position of the original value in the vector but in the sequence of the sorting in ascending order. The rank function is mostly used for ranking when we deal with ordinal variables, hence, we should use it whenever ranking of values is required, on the other hand, order is frequently used for ordering all numerical values.Examplesset.seed(100) x1

Read More

How to find the functions inside a package in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 24-Aug-2020 4K+ Views

There are so many packages in R and each of these packages have different objectives, thus, the number of functions in these packages are large enough to solve the problems in analysis. A package might have fifteen functions and the other might have hundred, it totally depends on the necessity. We can find the functions inside a package by using lsf.str function but we need to load the package prior to knowing the functions inside.Example1library(BSDA) lsf.str("package:BSDA") CIsim : function (samples = 100, n = 30, mu = 0, sigma = 1, conf.level = 0.95, type = "Mean") Combinations : function ...

Read More

How to extract a string that lies between two strings in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 24-Aug-2020 717 Views

If we have a long string then we might want to extract a part of string that lies between two strings. For example, if we have a string “E-learning changing the education system in the world” and we want to extract the string “the education system” brave then we must be very careful about passing the strings in string function, you get to know this in examples. The extraction is not difficult with gsub function but we have to make sure that we are using the correct syntax, otherwise, the result will become obnoxious.Examplesx1

Read More

How to find the number of runs in a sequence in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 24-Aug-2020 764 Views

Sometimes data is recorded as a sequence of numerical values or strings and we might to find the frequency for each of the sequences. This helps us to check the variation in the runs but we must make sure the total frequency is equal to the total number values, otherwise our calculation of frequency would be incorrect. To find the number of runs, we can use rle function in R that stands for Run Length Encoding.Examplesx1

Read More

How to add title at the top of multi-plots created by using gridExtra in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 24-Aug-2020 9K+ Views

The gridExtra package works as an alternative of par(mfrow) with ggplot2, therefore, we can create multiple plots using ggplot2 and gridExtra on a single plot window. Now, if we want to give a title to all of the plots or we can say if want to give a main title to multi-plots, the top argument will be used to make the title lie on the top of the title. Similarly, we can use bottom, left, and right on the basis of our requirement but we would also need grid package for this purpose.ExampleConsider the below data frame −set.seed(123) x1

Read More

How to get the US states name abbreviation in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 24-Aug-2020 641 Views

There are fifty states in United States, few of them have short names but most of the states have a lengthy name. Therefore, if we are dealing with data that has states name of United States then it will be a little complicated to access the states by using their name, hence it is preferred to use abbreviation. We can get the state name abbreviation with the help of state.abb function.Examplesstate.abb[which(state.name=="New York")] [1] "NY" state.abb[which(state.name=="California")] [1] "CA" state.abb[which(state.name=="Texas")] [1] "TX" state.abb[which(state.name=="Florida")] [1] "FL" state.abb[which(state.name=="Washington")] [1] "WA" state.abb[which(state.name=="Michigan")] [1] "MI" state.abb[which(state.name=="New Jersey")] [1] "NJ" state.abb[which(state.name=="Arizona")] [1] "AZ" state.abb[which(state.name=="Pennsylvania")] [1] "PA" state.abb[which(state.name=="Alaska")] ...

Read More

What are the restrictions on creating a vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 24-Aug-2020 270 Views

There are four main restrictions on creating a vector in R. We must remember these restrictions while creating any type of vector −A vector name cannot have % sign.A vector name cannot start with a number.A vector can start with a dot but it should not have a number after it.A vector cannot start with underscore.ExamplesVectors with % sign −x1%

Read More

How to find the correlation matrix by considering only numerical columns in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 24-Aug-2020 1K+ Views

While we calculate correlation matrix for a data frame, all the columns must be numerical, if that is not the case then we get an error Error in cor(“data_frame_name”) : 'x' must be numeric. To solve this problem, either we can find the correlations among variables one by one or use apply function.ExampleConsider the below data frame −set.seed(99) x1

Read More
Showing 51461–51470 of 61,299 articles
Advertisements