To create a vector of data frame values by rows we can use c function after transposing the data frame with t. For example, if we have a data frame df that contains many columns then the df values can be transformed into a vector by using c(t(df)), this will print the values of the data frame row by row.Example1 Live Demoset.seed(798) x1
To create a character vector in R we can enclose the vector values in double quotation marks but if we want to use a data frame values to create a character vector then as.character function can be used. For example, if we have a data frame df then all the values in the df can form a character vector using as.character(df[]).Example1 Live Demox1
Line types can be very different and they are helpful to differentiate among different variables. Mostly, it is used to plot trend data so that the trend for different variables can be visualized with a unique line. In R, we can use matplot function to create such type of multiple lines chart.Example1 Live DemoM1
A Polynomial regression model is the type of model in which the dependent variable does not have linear relationship with the independent variables rather they have nth degree relationship. For example, a dependent variable x can depend on an independent variable y-square. There are two ways to create a polynomial regression in R, first one is using polym function and second one is using I() function.Example1set.seed(322) x1
The relative frequency is the proportion of something out of total. For example, if we have 5 bananas, 6 guava, 10 pomegranates then the relative frequency of banana would be 5 divided by the total sum of 5, 6, and 10 that is 21 hence it can be also called proportional frequency.Example1 Live DemoConsider the below data frame −set.seed(21) x%mutate(freq=n/sum(n)) `summarise()` ungrouping output (override with `.groups` argument) # A tibble: 4 x 3Outputx n freq 1 A 3 0.15 2 B 7 0.35 3 C 7 0.35 4 D 3 0.15 Warning message: `...` is not empty. We ... Read More
In a bar plot, each bar represents one category of a single categorical variable but in a stacked bar plot, the bars represent same categorical variable but each divided into sub-categories. If we want to have similar distribution of colors in each bar then col argument with barplot function can be used.Example1 Live DemoM1
Often values are repeated that generate duplication in the data and we might want to get rid of those values if they are not likely to create bias in the output of the analysis. For example, if we have a column that defines a process and we take the output of the process five times but it takes the same output all the time then we might want to use only one output.Example1 Live DemoConsider the below data frame −ID
To extract the model equation model object, we can use the model object name with dollar sign and call function. For example, if we have a model object name Model then the model equation can be extracted by using Model$call. This will directly present the equation that was used to create the model.Example1 Live Demox1
Generally, the chart title is written on the upper side of the plot but sometimes we need to put it in the bottom. This is recommended in situations when the chart title explains something about the plot. For example, if we are plotting a normal distribution then we can use “Approximately Normal” as the chart title in the bottom because we know that perfect normal is a very rare event. If we want to set the chart title at the bottom in a chart created by using ggplot2 then we need to use grid.arrange function of gridExtra package.ExampleConsider the below ... Read More
The border thickness highlights the bars and this could be useful in situations where we have similar frequencies. If we want to change the thickness of the bars then size argument under geom_bar function of ggplot2 package can be used and it can be set according to our need starting from 1.ExampleConsider the below data frame −x