[關鍵字]: tidyr
[出處]: http://www.r-bloggers.com/tidyr-0-5-0/
[重點摘要]:
重點功能之一,也是我覺得有興趣的XD:
separate_rows() separates values that contain multiple values separated by a
delimited into multiple rows. Thanks to Aaron Wolen for the contribution!
df <- data_frame(x = 1:2, y = c("a,b", "d,e,f"))
df %>% separate_rows(y, sep = ",")
#> Source: local data frame [5 x 2]
#>
#> x y
#> <int> <chr>
#> 1 1 a
#> 2 1 b
#> 3 2 d
#> 4 2 e
#> 5 2 f
Compare with separate() which separates into (named) columns:
df %>% separate(y, c("y1", "y2", "y3"), sep = ",", fill = "right")
#> Source: local data frame [2 x 4]
#>
#> x y1 y2 y3
#> * <int> <chr> <chr> <chr>
#> 1 1 a b <NA>
#> 2 2 d e f