Reputation: 358
Is there a way to create a dataframe from 2 vectors row wise?
list1<- c('a','b','c')
list2<- c('x','y','z')
I'd like to create a DF from these 2 lists such that each of these 2 lists is a row in the DF.
Upvotes: 3
Views: 1146
Reputation: 79204
You could also use bind_rows
df <- bind_rows(x = list1, y = list2)
Output:
x y
<chr> <chr>
1 a x
2 b y
3 c z
Upvotes: 3
Reputation: 887851
One option is data.frame
data.frame(x = list1, y = list2)
# x y
#1 a x
#2 b y
#3 c z
Or if it should be otherway, use rbind
setNames(rbind.data.frame(list1, list2), c("x", "y"))
Upvotes: 5