Create a Data Frame from Vectors in R

Use the data.frame() function in R to create a data frame from vectors. The data frame in R is a two-dimensional array or table where each row contains the value of each column and the column contains the value for each variable. It can contain heterogeneous data. Vectors in R …

Read more

Export a Data Frame to CSV file in R

Using the write.csv function in base R, it can export a data frame to a CSV file. The write.csv function takes data frame and path of export to CSV file as the input parameters. Use the following syntax to write a data frame to the CSV file. R language provides …

Read more

Convert a Data Frame to Matrix in R

data.matrix() and as.matrix() functions in R is used to convert a data frame to matrix. The data.matrix() function converts all data frame variables to numeric and displays them as columns of the matrix. The as.matrix() is a generic function and returns a character matrix. In this tutorial, we will discuss …

Read more

Selecting Columns in R

Selecting columns from the data frame in R is very important when we have to analyze large data set. Using the dplyr package select() function, we can select specific columns by column name or column index. Using the base R, we can select specific columns from the data frame using …

Read more

How to Add Column to a Data Frame in R

Using the $ operator or square bracket, we can add a column to a data frame. We can create vector data and add it as a column to a data frame. Use the add_column function in the tibble package to add a new column or append vector to a data …

Read more

Convert List to Data Frame in R

Data frame in R stores heterogeneous data types in the format of tabular forms. It is a list of vectors of equal length. Converting a list to a data frame provides more insight to analyze the tabular format of data. The as.data.frame() function in R is used to create a …

Read more

Merge Data Frames in R

Merge data frames are quite useful when data is available in different data stores. The combining of data frames in R gives more insights to perform analysis of the dataset. Using merge() , rbind() functions, we can merge data frames in R. merge() is a built-in R function that merges …

Read more

R Sorting Data Frame by Column

Using the order() function in R, sort data frame by column. order() function as default sorts the data in ascending order. However using the minus (-) sign before the column, we can sort data frame by column in descending order. We can use the order() function to sort a data …

Read more

Dataframe Conditional Selection in R

Using the square bracket with conditional selection in the data frame, you can subset the data frame in r and extract the observations you would like to keep or exclude. You can also subsetting the data frame in r using the subset() function in R. In this tutorial, we will …

Read more