[英]Create Dataframe from vector rowwise
Is there a way to create a dataframe from 2 vectors row wise?有没有办法从 2 个向量行中创建 dataframe ?
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.我想从这两个列表中创建一个 DF,这样这两个列表中的每一个都是 DF 中的一行。
One option is data.frame
一种选择是
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
或者如果应该是其他方式,请使用
rbind
setNames(rbind.data.frame(list1, list2), c("x", "y"))
You could also use bind_rows
你也可以使用
bind_rows
df <- bind_rows(x = list1, y = list2)
Output: Output:
x y
<chr> <chr>
1 a x
2 b y
3 c z
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.