summary() Function: Producing Summary Statistics in R

R summary() Function

The summary() is a generic function that produces the summary statistics for various R objects, including vectors, matrices, data frames, and model objects. The above figure explains the summary for a data frame with three columns. For different types of objects, the summary() function produces different types of summaries: If the input is numeric, it … Read more

R paste() Function

R paste() Function

The paste() function in R concatenates vectors after converting them to character. paste(“Hello”, 19, 21, “Mate”) # Output: [1] “Hello 19 21 Mate” It helps us combine multiple strings or vectors into a single string or vector of strings, with customizable separators, constructing file paths and URLs, creating composite keys from multiple variables, manipulating text data, … Read more

paste0() Function in R

R paste0() Function

R paste0() function concatenates strings without any separator between them. It is a shorthand version of paste(…, sep = “”). paste0(“Data”, “Matics”) # Output: [1] “DataMatics” paste0(letters[18:22]) # Output: [1] “r” “s” “t” “u” “v” It is helpful for generating variable names, file paths, labels, and identifiers in a vectorized, compact way. Syntax paste0(…, collapse … Read more

How to Calculate Standard Error in R

How to Calculate Standard Error in R

Standard Error (SE) measures the variability or dispersion of the sample mean estimate of a population mean. Here are three ways to calculate standard error in R: Using sd() with length() Using the standard error formula Using std.error() from plotrix package Here is the basic formula: where: σ = sample standard deviation n = sample … Read more

R max() and min() Functions

R min() and max() Methods

max() The max() function in R finds the maximum value of a vector or data frame. For example,  if you have vec <- c(21, 19, 11, 2, 18, 3), then max(vec) will return 21. This function can be used with any data type that is coercible to a numeric type, including logical vectors where TRUE is … Read more

R as.Date() Function: Working with Dates

as.Date() Method in R

The as.Date() function in R converts various types of date and time objects or character strings into Date objects. Syntax as.Date(x, format, tryFormats = c(“%Y-%m-%d”, “%Y/%m/%d”), optional = FALSE, tz = “UTC”, origin, …) Parameters Name Description x It is an object to be converted. format It is a character string. If the format argument … Read more

R pnorm() Function [With Graphical Representation]

R pnorm() Method

The pnorm() function in R calculates the cumulative density function (cdf) value of the normal distribution given a specific random variable q, the population mean μ, and the population standard deviation σ. It returns the probability that a normally distributed random variable is less than or equal to a given value. It provides the probability … Read more

Converting Vector to String in R

Converting vector to string in R

You may want to convert a vector to a string when you need to combine vector elements into a single character string for data export. For example, exporting into csv, text, or database files. Here are three ways to convert a vector to a string in R: Using paste() Using paste0() Using toString() Method 1: … Read more

How to Set and Get Working Directory [setwd() and getwd()] in R

setwd() and getwd() in R

Set the current working directory The setwd() function sets the working directory to the new location, allowing us to change the default location for file operations. The working directory is a location where R looks for files to read or save by default. Use absolute paths for reliability, relative paths for flexibility. Syntax setwd(dir) Parameters … Read more