[分享] tidyr 0.5.0

作者: celestialgod (天)   2016-06-15 12:29:02
[關鍵字]: 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
作者: cywhale (cywhale)   2016-06-15 17:30:00
I also saw it, very helpful~~

Links booklink

Contact Us: admin [ a t ] ucptt.com