←
PDF 186 / 520 Exercises
→
English · PDF 186
Original PDF page 186
中文 · PDF 186

#> 5 中国 19_99 212258/1272915272 #> 6 中国 20_00 213766/1280428583

A comparison table comparing country rates for 1999 and 2000 between Afghanistan and Brazil. The table shows rates for Afghanistan (1999, 2000) and Brazil (1999, 2000). A large arrow points from the table to the table below, labeled 'table 6'.

国家 年份 比率 国家 世纪 年份 比率
阿富汗 1999 745 / 19980771 阿富汗 19 99 745 / 19980771
阿富汗 2000 2666 / 20595360 阿富汗 20 0 2666 / 20595360
巴西 1999 37737 / 172006362 巴西 19 99 37737 / 172006362
巴西 2000 80488 / 174504898 巴西 20 0 80488 / 174504898
中国 1999 212258 / 1272915272 中国 19 99 212258 / 1272915272
中国 2000 213766 / 1280428583 中国 20 0 213766 / 1280428583

图 9-5. 合并 table5 使其整洁

在这个例子中我们还需要使用 sep 参数。默认值会在来自不同列的值之间放置一个下划线(_)。这里我们不想要任何分隔符,所以我们使用 "":

table5 %>% unite(new, century, year, sep = "") #> # A tibble: 6 × 3 #> country new rate #> * #> 1 Afghanistan 1999 745/19987071 #> 2 Afghanistan 2000 2666/20595360 #> 3 Brazil 1999 37737/172006362 #> 4 Brazil 2000 80488/174504898 #> 5 China 1999 212258/1272915272 #> 6 China 2000 213766/1280428583

练习

    1. separate() 中的 extra 和 fill 参数有什么作用?请对下面两个玩具数据集尝试各种选项:

tibble(x = c("a,b,c", "d,e,f,g", "h,i,j")) %>% separate(x, c("one", "two", "three"))

tibble(x = c("a,b,c", "d,e", "f,g,i")) %>% separate(x, c("one", "two", "three"))

    1. unite() 和 separate() 都有一个 remove 参数。它的作用是什么?为什么你会把它设置为 FALSE?