Create Dataframe in R Programming Language

To create an R data frame use data.frame() function and then pass each of the vectors you have created as arguments to the function.

R




# R program to create dataframe
 
# creating a data frame
friend.data <- data.frame(
    friend_id = c(1:5),
    friend_name = c("Sachin", "Sourav",
                    "Dravid", "Sehwag",
                    "Dhoni"),
    stringsAsFactors = FALSE
)
# print the data frame
print(friend.data)


Output:

  friend_id friend_name
1 1 Sachin
2 2 Sourav
3 3 Dravid
4 4 Sehwag
5 5 Dhoni

R – Data Frames

R Programming Language is an open-source programming language that is widely used as a statistical software and data analysis tool. Data Frames in R Language are generic data objects of R that are used to store tabular data. 

Data frames can also be interpreted as matrices where each column of a matrix can be of different data types. R DataFrame is made up of three principal components, the data, rows, and columns. 

Similar Reads

R Data Frames Structure

As you can see in the image below, this is how a data frame is structured....

Create Dataframe in R Programming Language

To create an R data frame use data.frame() function and then pass each of the vectors you have created as arguments to the function....

Get the Structure of the R Data Frame

...

Summary of Data in the R data frame

One can get the structure of the R data frame using str() function in R....

Extract Data from Data Frame in R

...

Expand Data Frame in R Language

In the R data frame, the statistical summary and nature of the data can be obtained by applying summary() function....

Access Items in R Data Frame

...

Amount of Rows and Columns

Extracting data from an R data frame means that to access its rows or columns. One can extract a specific column from an R data frame using its column name....

Add Rows and Columns in R Data Frame

...

Remove Rows and Columns

A data frame in R can be expanded by adding new columns and rows to the already existing R data frame....

Combining Data Frames in R

...