In this article we will see how to create a Dataframe from four given vectors in R. To create a data frame in R using the vector, we must first have a series of vectors containing data. The data.frame() function is used to create a data frame from vector in R.
Syntax:
data.frame(vectors)
Example 1. Creating dataframe from given 4 vectors.
R
id = c (1, 2, 3)
name = c ( "karthik" , "nikhil" , "sravan" )
branch = c ( "IT" , "CSE" , "IT" )
favourite_subject = c ( "SE" , "DAA" , "OS" )
df1= data.frame (id, name, branch, favourite_subject)
print (df1)
|
Output:

Example 2:
R
faculty_id = c (247, 143, 01768)
faculty_name= c ( "Subbarao" , "praveen kumar" , "sujatha" )
designation= c ( "accociate professor" , "assistant professor" ,
"accosiate professor" )
salary = c (60000, 50000, 60000)
df3 = data.frame (faculty_id, faculty_name, designation,salary)
print (df3)
|
Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
24 Mar, 2022
Like Article
Save Article