dplyr主要用于处理dataframe数据,并植入C++技术以增加运算速度。
点 .
类似于~的一种符号,只收集变量名,而不是名下的值,plyr包多是用“.”来设定变量名表达式。
输出:list of symbol and language primitives
%>%、 %.%
mtcars %>%
head() %>%
print() %>%
add_rownames()
add_rownames
为dataframe增加行名。
all.equal.tbl_df
比较两个dataframe是否相同。
arrange
arrange(mtcars, cyl, disp)
根据cyl,disp的大小排列行(升序)
arrange(mtcars, desc(disp))
##此为降序
as_data_frame
强制转换list为dataframe。
between
x <- rnorm(1e2)
x[between(x, -1, 1)]
between(x, -1, 1)返回TRUE或者FALSE。
mutate
增加新变量。
glimpse
查看数据。
each
联合函数,但不能输入额外的参数。
# Call min() and max() on the vector 1:10
each(min, max)(1:10)
# This syntax looks a little different. It is shorthand for the
# the following:
f<- each(min, max)
f(1:10)
# Three equivalent ways to call min() and max() on the vector 1:10
each("min", "max")(1:10)
each(c("min", "max"))(1:10)
each(c(min, max))(1:10)
# Call length(), min() and max() on a random normal vector
each(length, mean, var)(rnorm(100))