How to combine multiple vectors in one data frame in R ?
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answer ( 1 )
To combine multiple vectors into a data frame, you simply add all vectors as arguments to the data.frame() function, separated by commas. R will automatically create a data frame with the variables that are named the same as the vectors used.
Eg: Create the following vectors,
> member amount joined member.data str(member.data)
‘data.frame’: 3 obs. of 3 variables:
$ member : Factor w/ 3 levels “Avantika”,”Aayush”,..: 1 3 2
$ amount : num 21500 22000 28700
$ joined: Date, format: “2010-11-01” “2008-03-25” …
This is how you combine multiple vectors in one data frame in R.