How to Use Dollar($) Sign in R

How to Use Dollar($) Sign in R

In R, the dollar sign ($) is used to access elements (columns) of a list or a data frame by name. You can also use the $ operator to add, update, and delete variables from the list and data frame columns. This operator is somewhat limited in programmability. For example, you can’t easily use a … Read more

R as_tibble() Function

as_tibble() in R

The as_tibble() function in R is used to convert objects like data frames, lists, or matrices into tibbles. Tibbles are a modern take on data frames but with some added conveniences and changes to behavior. A tibble is a type of data frame with advantages over regular data frames, such as enhanced printing and subsetting. … Read more

How to Calculate Square in R

How to Calculate Square in R

Here are four ways to calculate a square in R: Using ^ operator Using * operator Using ** operator Using sapply() Method 1: Using ^ operator The ^ is an arithmetic operator used to find the exponent of the vector. Example 1: Calculating the square of a single value Figure 1: Calculating a square value of a vector rv … Read more

Not equal (!=) Operator in R

Not equal (!=) Operator in R

In R, the not equal (!=) operator is used to test inequality between two objects. It checks whether its left-hand and right-hand operands are not equal and returns a logical value (TRUE or FALSE) for each comparison. Syntax operand1 != operand2 operand1 and operand2 can be numbers, variables, vectors, or comparable objects. Visual Representation Example … Read more

R split() Function

R split() Function

The split() function is used to divide data into groups based on some criteria, typically defined by a factor or list of factors. This method is robust when combined with lapply() or sapply() for applying functions to each subset of data. Syntax split(x, f, drop = FALSE) Parameters x: It is a data frame or … Read more

How to Rename Data Frame (Single and Multiple) Columns in R

Rename Data Frame (Single and Multiple) Columns in

Here are the five ways to rename a data frame column in R: Using colnames() Using names() Using rename() from dplyr package Using rename_with() from dplyr package Using setnames() from data.table package Method 1: Using colnames() The colnames() function is used to set or get the names of a data frame column. You can use it to rename … Read more

R strftime() Function

strftime() Function in R

The strftime() function in R is used for formatting date and time objects. It converts dates and times to a specified format, making it a helpful function for manipulating and displaying date-time data in a more readable or desired format. Syntax strftime(time) Parameters time: It is a time object. Common Format Specifications %Y: Year with … Read more

R strptime() Function

R strptime() Function

The strptime() function is used for parsing characters to time objects based on a specified format. It is an inverse of the strftime() function and is particularly helpful when you have dates and times as character strings. It’s important to correctly specify the format that matches the structure of your date-time string. If the format … Read more

R dim() Function

R dim() Function

The dim() function in R is used to get or set the dimensions of a  matrix, array, or data frame. For example, dim(df) returns the dimensions of df, and dim(df) <- c(3, 3) sets the dimensions for df, which has 3 rows and 3 columns. The total number of elements must remain constant when reshaping … Read more

R match() Function

R match() Function

The match() function in R is used to find the positions of (first) matches of its first argument in its second argument. If an element is not found, it returns NA. The function returns the position of the first match if there are multiple matches. Syntax match(data, table, nomatch = NA_integer_, incomparables = NULL) Parameters … Read more