R dnorm(): Probability Density Function

dnorm() in R

The dnorm() function in R calculates the value of the probability density function (pdf) of the normal distribution of a given value or vector of values. It determines the probability density of a continuous random variable following a normal distribution, characterized by a mean (μ) and standard deviation (σ). How do you define the normal … Read more

R rep() Function: Repeating Elements of a Vector

R rep() Method

R rep() is a generic function that replicates elements of vectors and lists for a specific number of times. The best use case is when working with time-series analysis; you may want to repeat certain values to simulate specific conditions and obtain an accurate output, which is where the rep() function is helpful. Syntax rep(vec, times = 1, … Read more

Splitting Strings: A Beginner’s Guide to strsplit() in R

R strsplit() Method

The strsplit() function in R splits elements of a character vector into a list of substrings based on a specified delimiter or regular expression pattern. In the above figure, we are splitting a character vector “string” into three substrings based on the space in between them. string <- (“Hello dystopian world”) strsplit(string, split = ” … Read more

Understanding of rnorm() Function in R

What is rnorm() function in R

The rnorm() method in R generates random numbers from a normal (Gaussian) distribution, which is characterized by a bell-shaped curve defined by its mean and standard deviation, which are widely used in statistical simulations and data analysis. To understand in simple terms, let me take an example.  Let’s say I want to select some candies. … Read more

as.factor() in R: Converting a Vector to Categorical Data

R as.factor() Function

The as.factor() function in R converts a vector object into a factor. Factors store unique values as levels and are essential for statistical modeling, data visualization, and ensuring the proper handling of categorical data in analyses. The above figure perfectly describes the conversion from vector to factor. The main difference between factor() and as.factor() is … Read more

cbind() Function: Binding R Objects by Columns

cbind() Method in R

R cbind (column bind) is a function that combines specified vectors, matrices, or data frames by columns, creating a new matrix or data frame where the input objects are placed side by side. Syntax cbind(…, deparse.level = 1) Parameters Argument Description … It represents the objects that we need to combine column-wise. It can be … Read more

rbind() Function: Binding Rows in R

R rbind() method

The rbind() function combines R objects, such as vectors, matrices, or data frames, by rows. It stacks rows vertically. The above figure illustrates how the rbind() method works on data frames, combining their rows. The data frame that is being stacked must have the same number of columns (or elements, in the case of vectors), … Read more

as.numeric(): Converting to Numeric Values in R

R as.numeric() Method

The as.numeric() function in R converts valid non-numeric data into numeric data. What do I mean by valid non-numeric data? They are valid numeric values that are stored as text or categorical variables (factors). For example, “1” is a valid non-numeric data but “A” is not valid non-numeric data as far as the as.numeric() method … Read more

Dollar Sign ($ Operator) in R

Dollar operator ($) in R

In R, you can use the dollar sign ($ operator)  to access elements (columns) of a list or a data frame by their name. It also works with your environment. For example, it can fetch you the current environment variables. With its help, you can add, modify, or delete variables from the list and data … Read more