How to Create a Data Frame from Vectors in R

Creation of Data Frame from vectors

To create a data frame from vectors in R, use the data.frame() function and pass the vectors. Ensure you have the same length of all the vectors; otherwise, it throws an error. The above figure shows five vectors. Each vector has its own type and the same length, which is five. After converting vectors to … Read more

R append() Function: Complete Guide

append() function in R

The append() function in R concatenates values to a vector or list at a specified position. It returns a new object without modifying the original. You can add a single or multiple elements to a vector or list. Syntax append(obj, values, after = length(x)) Parameters Name Value obj It is an original vector or list. … Read more

How to Remove the First Row of DataFrame in R

Removing first row from Data Frame

Here are three ways to remove the first row of a data frame in R: Using negative indexing Using dplyr::slice() Using tail() Method 1: Using negative indexing Negative indexing is a method for excluding specific rows based on your requirements. Since we need to remove the first row, we can use df[-1, ], where -1 … Read more

How to Remove Duplicates from a Vector in R

Remove Duplicates from a Vector in R

In R, unique() and subsetting with !duplicated() are efficient ways to remove duplicates. Duplicate elements in a vector refer to those elements that appear more than once. Duplicates can skew the data analysis and lead to inaccurate results. Removing them leads to more reliable insights. Method 1: Using unique() The unique() function is a one-step, … Read more

How to Round Numbers in R

How to Round Numbers in R

Here are five ways to round numbers in R: Using round() Using signif() Using ceiling() Using floor() Using trunc() Rounding is a process of approximating a number to a shorter, more straightforward, and interpretable value while retaining its closeness to the original value. Here are some basic different types of rounding we use in our … Read more

Converting String to Uppercase in R

Featured Image of Converting String to Uppercase in R

For string operations like comparing strings, data standardization, formatting output, or input validation, we may want to convert the input to uppercase (or lowercase, depending on the situation) to ensure consistency and prevent errors caused by inconsistent capitalization. The toupper() function converts a string to an upper case. It accepts an input string and converts … Read more

R names() Function

Featured Image of R names() Function

The names() function in R gets or sets the names of objects such as vectors, lists, or data frames. If you are using it to fetch the name, it will return a character vector containing the names assigned to its elements or columns. Syntax names(obj) # To get names names(obj) <- value # To set names Parameters Name Value … Read more