#title dplyr [[TableOfContents]] ==== inner join ==== {{{ > data1 id mid 1 23 43 2 4 56 3 78 29 4 54 99 > data2 id final 1 4 77 2 23 2 3 54 19 4 70 31 > dplyr::inner_join(data1, data2, by="id") id mid final 1 23 43 2 2 4 56 77 3 54 99 19 }}} ==== 첫 5행만 ==== {{{ dplyr::filter(df, row_number() <= 5) }}} ==== 기본 예제 ==== {{{ #install.packages("dplyr") library("dplyr") df <- tbl_df(iris) df class(df) #필터 filter(df, Species == "setosa", Sepal.Length >= 4) filter(df, Species == "setosa" | Species == "versicolor") #정렬 arrange(df, Sepal.Length, desc(Sepal.Width)) #특정 컬럼만 조회 select(df, Sepal.Length, Species) select(df, -Species) select(df, Sepal.Width:Petal.Width) select(df, -(Sepal.Width:Petal.Width)) #열추가 mutate(df, compute = Sepal.Length * Sepal.Width, total.Sepal.Length = sum(Sepal.Length)) transform(df, compute = Sepal.Length * Sepal.Width, total.Sepal.Length = sum(Sepal.Length)) #집계 summarise(df, total=sum(Sepal.Length)) summarise(group_by(df, Species), total=sum(Sepal.Length)) #chain 기능 group_by(df, Species) %>% filter(Sepal.Length >= 5) %>% summarise(total=sum(Sepal.Length)) }}} ==== 참고자료 ==== * [https://github.com/dgrapov/TeachingDemos/blob/master/Demos/dplyr/hands_on_with_dplyr.md 참고:Hands-on with dplyr] * attachment:RTips/data-wrangling-cheatsheet.pdf * attachment:RTips/data_table_cheat_sheet.pdf