Create a Data Frame with Values and column Names
R
# Define the data id <- c (1, 2, 3) names <- c ( "Vipul" , "Jayesh" , "Shivang" ) address <- c ( "123 Main St" , "456 Oak St" , "789 Pine St" ) phone <- c ( "555-1111" , "555-2222" , "555-3333" ) aadhaar_no <- c ( "123-456-789" , "456-789-123" , "789-123-456" ) # Combine vectors into a data frame myData <- data.frame ( ID = id, Names = names, Address = address, Phone = phone, `Aadhaar No` = aadhaar_no ) # Display the data frame print (myData) |
Output:
ID Names Address Phone Aadhaar.No
1 1 Vipul 123 Main St 555-1111 123-456-789
2 2 Jayesh 456 Oak St 555-2222 456-789-123
3 3 Shivang 789 Pine St 555-3333 789-123-456
Create empty DataFrame with only column names in R
In this article, we are going to discuss how to create a data frame in r with column names and create an empty data frame with column names in the R Programming Language.
The basic syntax for creating a data frame is using data. frame().