使用R中的列表将重复添加到数据框中的列

时间:2016-09-30 20:13:31

标签: r dataframe

你好简单的R问题,但是List_A中每个项目在数据框架中重复一次List_B中每个项目的最佳方法是什么。

List_A = c("a","b","c")
List_B = c("one","oneb","two","twoa","three","threea")

期望的输出:

data.frame(List_A = c("a","a","a","a","a","a","b","b","b","b","b","b","c","c","c",,"c","c","c"),
List_B = c("one","oneb","two","twob","three","threeb","one","oneb","two","twob","three","threeb","one","oneb","two","twob","three","threeb"))

1 个答案:

答案 0 :(得分:2)

按照@HubertL建议后,我能够获得重复List_B的数据框。

expand.grid(List_A=List_A, List_B=List_B)