To create combination of multiple vectors, we can use expand.grid function. For example, if we have six vectors say x, y, z, a, b, and c then the combination of vectors can be created by using the command expand.grid(x,y,z,a,b,c).Example Live Demox1
If we have a character column in an R data frame then we might want to check whether a particular value exist in the column or not. For example, if we have a gender column then we might want to check whether transgender exists in that column or not. This can be done with the help of grepl function. Check out the below examples to understand how it works.Consider the below data frame −Example Live Demox
To extract statistical summary from boxplot we can use stats function with delta operator. For example, if we have a data frame called df that contains 5 columns then the boxplot for each column can be created by using the command boxplot(df) and if we want to extract the statistical summary from this boxplot then boxplot(df)$stats can be used.Consider the below data frame −Example Live Demodf
Suppose we have a vector that contains multiple string elements and we want to find out which string element has a particular substring. This can be done with the help of grep function. For example, if we have a vector called x that contains five string elements each of varying length then finding which of the elements has a substring say programming then it can be done by using the command grep("programming",x,fixed=TRUE)Example Live Demox1
To put space between words that start with uppercase letter in string vector in R, we can use gsub function. Since we can have uppercase letters as well as lowercase letters in the string vector hence, we need to properly specify both type of characters for creating the space between words. Check out the below examples to understand how it works.Example Live Demox1
The most difficult problem in data analysis is cleaning a dirty data. Most of the times the data is available in dirty form and one such dirtiness is a string vector having unnecessary values after a particular character. Therefore, to truncate a string vector after a character we can use str_split from stringr package along with the sapply function as shown in the below examples.library(stringr)Example Live Demox1
When we have a Euro currency column in an R data frame as a response variable then we might to display the Euro sign in the plot created by using ggplot2 package. For this purpose, we can use scales package and the scale for Y axis will be changed by using the command scale_y_continuous(labels=dollar_format(suffix="€",prefix="")) to the plot command.Consider the below data frame −Example Live Demox
If a sequence is increasing by 1 that means for every value the total number of values increases by that much. For example, the values 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 are creating a sequence of values starting from 1 to 5. To create such type of sequences in R, we can simply use sequence function and pass the range as sequence(1:5).Example Live Demox1
To sort a large number of csv files in ascending order, we can use mixedsort function from gtools package. For example, if we have a list of csv files that are randomly arranged in a vector called FILES then the files can be sorted in ascending order using the command mixedsort(sort(FILES))Example Live DemoFiles1
Sorting a column of data.table object can be done easily with column number but sorting with column name is different. If a column name is stored in a vector and we want to sort a column of data.table object in ascending order using this name then order function will be used with single and double square brackets as shown in the below examples.Loading data.table package and creating a data.table object −Examplelibrary(data.table) x1