我有以下两个数据框。
首先,我有职业数据框。下面是示例数据框
state <- c("00","00","32","32")
codetype <- c("19","19","19","19")
code <- c ("123456","123457","123456","123457")
codetitle <- c("doctors","lawyers","doctors","lawyers")
first <- data.frame(state,codetype,code,codetitle)
第二, Dataframe 是这个
state <- c("01","01","04","04","05","05")
codetype <- c("19","19","19","19","19","19")
code <- c("123456","123457","123456","123457","123456","123457")
pct10 <- c(12.30,12.65,14.50,14.23,15.65,25.22)
second <- data.frame(state,codetype,code,pct10)
所需的任务是这样的..需要在第一个数据框中创建新行。所需的结果是从第二个数据框中获取唯一的状态值,并在第一个数据框中创建相同的行..只是在开始时使用新的状态值。我知道我使用expand_grid。我唯一真实的困惑的是如何
预期结果
state codetype code codetitle
32 19 123456 Doctors
32 19 123457 Lawyers
00 19 123456 Doctors
00 19 123457 Lawyers
01 19 123456 Doctors
01 19 123457 Lawyers
04 19 123456 Doctors
04 19 123457 Lawyers
05 19 123456 Doctors
05 19 123457 Lawyers
3条答案
按热度按时间1qczuiv01#
也许是这样:
7hiiyaii2#
或者,您可以将
plyr::rbind.fill
与left join
一起使用创建于2023年2月6日,使用reprex v2.0.2
djmepvbi3#
可以使用
expand.grid()
函数创建所需的结果: